Re: array walk and class member functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux