You are here: Re: array walk and class member functions « PHP « IT news, forums, messages
Re: array walk and class member functions

Posted by Jason Barnett on 10/06/73 11:05

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация