Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.php Subject: Re: set_error_handler(): duplicate error Date: Sun, 20 Jun 2021 13:02:40 +0200 Lines: 66 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 7bit X-Trace: individual.net ofu9djPlnP2PLhoEObc28QFHJBZwVwGOoiSOdi6JxAWH3Zc8bi Cancel-Lock: sha1:X0HXtV1HQzwdHPVEWpgys2K7wak= In-Reply-To: Xref: csiph.com comp.lang.php:18666 Jerry Stuckle: [...] > set_error_handler() requires a real function as its parameter, not > something dynamically defined. set_error_handler() requires a *callable* not a function. An anonymous function is just fine - as this *is* a callable. This applies to *every* function in PHP which wants a callable and is quite handy to avoid declaring new functions if you just need it once for a specific callback: ------------------------------------------- 1, 'y' => 2 ], [ 'x' => 6, 'y' => 1 ], [ 'x' => 3, 'y' => 7 ], ]; usort( $array, function($a, $b) { if ($a['x'] == $b['x']) { return 0; } else if ($a['x'] > $b['x']) { return 1; } else { return -1; } } ); print_r($array); ------------------------------------------- Result: Array ( [0] => Array ( [x] => 1 [y] => 2 ) [1] => Array ( [x] => 3 [y] => 7 ) [2] => Array ( [x] => 6 [y] => 1 ) ) -- Arno Welzel https://arnowelzel.de