Re: array walk and class member functions

From: Date: Wed, 12 Jan 2005 12:49:33 +0000
Subject: Re: array walk and class member functions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-206174@lists.php.net to get a copy of this message
Tom wrote:
Hi I'm batting my head against a wall on this one... I have a class that has a constructor which sets some initial conditions, and then a public function that does some work. I want to be able to call this function from an external array_walk call, but when I try and reference it as $myClass->myFunction in the array_walk call, I get an error back saying that this is an invalid function.
Allow Monty Python to help you. <?php class aClass { function aMemberFunction($value, $key, $stuff) {
    print_r("$key: $value.  $stuff!\n");
} } $myArray = array("item1"=>"firstItem", "item2"=>"secondItem"); $myClass = new aClass; $stuff = "Your father was a hamster, and your mother smelled of Elderberries!"; array_walk($myArray, array($myClass, 'aMemberFunction'), $stuff); ?> -- Teach a person to fish... Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html PHP Manual: http://www.php.net/manual/en/index.php php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2

« previous php.general (#206174) next »