Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"call to undefined function" error when calling class method

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!";}         };       } } 
like image 970
Tommy Arnold Avatar asked Jan 26 '11 20:01

Tommy Arnold


1 Answers

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() 

or a method

$object->assign() 

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() 
like image 183
KingCrunch Avatar answered Sep 28 '22 05:09

KingCrunch