本文介紹了“調用未定義的函數"調用類方法時出錯的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送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模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!