“调用未定义的函数"调用类方法时出错

时间:2023-04-21
本文介绍了“调用未定义的函数"调用类方法时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

这是错误致命错误:调用未定义的函数assign(
这是代码,正如你所看到的,我显然已经定义了函数,为什么它不起作用

this is the error Fatal error: Call to undefined function assign(
this is the code, as you can see i obviously have defined the function so why is it not working

class shades {
    function create($name, $shades, $slug, $shortDesc, $longDesc, $position){
        $name = sanitize_paranoid_string($name);
        $slug = slug($name);
        $shortDesc = sanitize_sql_string($shortDesc);
        $longDesc = sanitize_sql_string($longDesc);
        $query = mysql_query("INSERT INTO products (type, name, slug, shortDesc, htmlDesc, position)VALUES('shades','$name','$slug','$shortDesc','$longDesc','$position')")or die(mysql_error());  
        $ID = mysql_insert_id();
        assign($shades, $ID);
        if($query) {return true;}
        else {return false;};
    }
    function delassign($toID){
        mysql_query("DELETE FROM assign WHERE type='shades' AND toID='$toID'")or die(mysql_error());    
    }
    function assign($shades, $toID)
    {
        foreach($shades as $shade)
        {
            $result = mysql_query("INSERT INTO assign(type, typeID, toID)VALUES('shades','$shade','$toID')")or die(mysql_error());
            if($result){echo "Added!";}
            else{echo"Not Added!";}
        };  
    }
}

推荐答案

您没有名为 assign() 的函数,但有一个具有此名称的方法.PHP 不是 Java,在 PHP 中你必须明确,如果你想调用一个函数

You dont have a function named assign(), but a method with this name. PHP is not Java and in PHP you have to make clear, if you want to call a function

assign()

或方法

$object->assign()

在您的情况下,对函数的调用驻留在另一个方法中.$this 总是指对象本身,其中存在一个方法.

In your case the call to the function resides inside another method. $this always refers to the object, in which a method exists, itself.

$this->assign()

这篇关于“调用未定义的函数"调用类方法时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:PHP 类:全局变量作为类中的属性 下一篇:检查方法是否存在于同一个类中

相关文章

最新文章