note 91169 deleted from function.usort by cmb

From: Date: Sun, 13 Oct 2019 08:15:32 +0000
Subject: note 91169 deleted from function.usort by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212633@lists.php.net to get a copy of this message
Note Submitter: huskyr at gmail dot com ---- 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.

« previous php.notes (#212633) next »