Re: Using usort() in a class

From: Date: Wed, 28 Jun 2000 06:28:04 +0000
Subject: Re: Using usort() in a class
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-22590@lists.php.net to get a copy of this message
----- Original Message ----- From: Kristian Koehntopp <kris@koehntopp.de> To: <php-dev@lists.php.net> Sent: Wednesday, June 28, 2000 7:51 AM Subject: [PHP-DEV] Using usort() in a class > Bjoern Hoermann reported: > > >From: Bjoern Hoehrmann <bjoern@hoehrmann.de> > >Newsgroups: de.comp.lang.php > >Subject: usort() und Sortierfunktion in Klasse > >Date: Tue, 27 Jun 2000 20:17:10 +0200 > > ... > > <? > class c1 { > function cmp($a, $b) { > echo "\$a : \$b -> $a: $b\n"; > } > function s($arr) { > usort($arr, $this->cmp); > return $arr; > } > } > > $c = new c1; > $a = array("a", "b", "5", "xlon", "ioa", > "-98", "q@", "ac"); > $c->s($a); > > > cmp() will not be called ($this->cmp reported as an unset variable) > and if you use '$this->cmp()' in the call, it will be called once > with $a and $b undefined. > > Can usort() be used in classes? Try using usort($arr, array($this,"cmp")); I haven't tested it though :) Regards Stefan

« previous php.dev (#22590) next »