Re: [PHP] function within a class function
On 21 June 2010 00:45, Rick Pasotto r...@niof.net wrote: Within a class function I have defined another function for use with the usort() function. How do I reference it? When it's not part of a class usort($arr,cmp) works fine but when it's within a class function I get this error: PHP Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION Is it not in the scope of the class function? -- Memory is like an orgasm. It's a lot better if you don't have to fake it. -- Seymour Cray (on virtual memory) Rick Pasotto r...@niof.net http://www.niof.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ?php class foo { public $array = array(3,2,1); private function cmp($a, $b) { return $a === $b ? 0 : ($a $b ? -1 : 1); } public function bar() { usort($this-array, array($this, 'cmp')); } } $baz = new foo(); $baz-bar(); print_r($baz-array); or ?php class foo { public $array = array(3,2,1); public function bar() { usort($this-array, function($a, $b) { return $a === $b ? 0 : ($a $b ? -1 : 1); }); } } $baz = new foo(); $baz-bar(); print_r($baz-array); if you have closures available to you. -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] function within a class function
Within a class function I have defined another function for use with the usort() function. How do I reference it? When it's not part of a class usort($arr,cmp) works fine but when it's within a class function I get this error: PHP Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION Is it not in the scope of the class function? -- Memory is like an orgasm. It's a lot better if you don't have to fake it. -- Seymour Cray (on virtual memory) Rick Pasottor...@niof.nethttp://www.niof.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function within a class function
On Sun, Jun 20, 2010 at 08:47:53PM -0400, Brandon Rampersad wrote: $this-usort(); self::usort(); On Sun, Jun 20, 2010 at 7:45 PM, Rick Pasotto r...@niof.net wrote: Within a class function I have defined another function for use with the usort() function. How do I reference it? When it's not part of a class usort($arr,cmp) works fine but when it's within a class function I get this error: PHP Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION Is it not in the scope of the class function? Forgive my ignorance but I have absolutely no idea what you're trying to tell me. usort() is part of the language so when, why, how does it become an object of some class? -- We have rights, as individuals, to give as much of our own money as we please to charity; but as members of Congress we have no right so to appropriate a dollar of public money. -- David Crockett Rick Pasottor...@niof.nethttp://www.niof.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php