note 91169 added to function.usort
| From: | huskyr at gmail dot com | Date: | Thu, 28 May 2009 13:04:49 +0000 |
| Subject: | note 91169 added to function.usort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156108@lists.php.net to get a copy of this message | ||
Remember that functions inside of functions will become part of the global scope too. So, something
like:
<?php
function foo($array) {
function compare($a,$b) {
return $a < $b;
}
usort($array, "compare");
return $array;
}
function bar($array) {
function compare($a,$b) {
return $a > $b;
}
usort($array, "compare");
return $array;
}
foo($something);
bar($something_else);
?>
Will result in a fatal error because you're redeclaring 'compare'. This could be a
little strange, e.g. for JavaScript programmers who expect functions in functions to become private
outside of the parent scope.
----
Server IP: 83.137.20.135
Probable Submitter: 80.79.35.18
----
Manual Page -- http://www.php.net/manual/en/function.usort.php
Edit -- https://master.php.net/note/edit/91169
Del: integrated -- https://master.php.net/note/delete/91169/integrated
Del: useless -- https://master.php.net/note/delete/91169/useless
Del: bad code -- https://master.php.net/note/delete/91169/bad+code
Del: spam -- https://master.php.net/note/delete/91169/spam
Del: non-english -- https://master.php.net/note/delete/91169/non-english
Del: in docs -- https://master.php.net/note/delete/91169/in+docs
Del: other reasons-- https://master.php.net/note/delete/91169
Reject -- https://master.php.net/note/reject/91169
Search -- https://master.php.net/manage/user-notes.php