stdClass object methods

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bertus
Forum Newbie
Posts: 1
Joined: Tue Oct 27, 2009 12:19 pm

stdClass object methods

Post by bertus »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hello.

I can define properties (data members) but I cant define a method for an object belongs to stdClass(generic) class.

for example :

Code: Select all

$myObject = new stdClass();
 
$myObject->prop1 = "hello";// works OK
 
function fun1() 
{
  echo  "bye";
}
 
$myObject->metodo1 = fun1; // object accept the asignament
 
$myObject->metodo1();
the last sentence show an error :
server message :

Fatal error: Call to undefined method stdClass::metodo1() in /home/.../public_html/pru/objetos.php on line 63


Thanks for any help.

bertus


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: stdClass object methods

Post by requinix »

Can't be done.
Post Reply