Re: [PHP4BETA] passing a method to usort

From: Date: Tue, 29 Feb 2000 21:43:13 +0000
Subject: Re: [PHP4BETA] passing a method to usort
Groups: php.version4 
Request: Send a blank email to php-version4+get-11212@lists.php.net to get a copy of this message
-----Original Message----- From: chagenbu@wso.williams.edu <chagenbu@wso.williams.edu> To: php4beta@lists.php.net <php4beta@lists.php.net> Date: Tuesday, February 29, 2000 4:16 PM Subject: [PHP4BETA] passing a method to usort >Should this work in php4? > ><?php > >error_reporting(E_ALL); > >class Sort { > function cmp ($a, $b) { > if ($a == $b) return 0; > elseif ($a > $b) return 1; > else return -1; > } >} > >$list = array(1, 4, 5, 2, 6, 3); >echo implode('<br>', $list); >echo '<hr>'; > >usort($list, 'Sort::cmp'); The following did not work for me either: $sorter=new Sort; usort($list,'$sorter->cmp'); I would guess that usort requires the name of a function, not an object method. > >echo implode('<br>', $list); >?> > > >It seems to just ignore the function completely, and doesn't touch the list. > >-chuck > >-- >PHP 4.0 Beta Mailing List <http://www.php.net/version4/> >To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net >For additional commands, e-mail: php4beta-help@lists.php.net >To contact the list administrators, e-mail: php4beta-admin@lists.php.net >

« previous php.version4 (#11212) next »