|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-01-08 11:53 UTC] johannes@php.net
[2007-01-09 04:21 UTC] a at b dot c dot de
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 01:00:02 2025 UTC |
Description: ------------ Object callbacks $foo->bar() are represented as arrays array($foo, 'bar'). Since PHP now supports the syntax $foo->bar->baz(), it seems at first sight that callback arrays could be nested similarly. Currently to use the baz() method above in a callback, one must use a temporary variable $temp=$foo->bar, and use array($temp, 'baz') as the callback in the same way that in PHP4 it was necessary to write $temp=$foo->bar; $temp->baz(). It would seem syntactically unambiguous to write the callback as array(array($foo, 'bar'), 'baz'). There is the matter that its first element refers to an object, not a method, but that's what the first element of an array callback is supposed to refer to (static class methods notwithstanding). Reproduce code: --------------- <?php class aclass { public $b; } class bclass { public function foo($v) { return $v*2; } } $t = array('1','2','3','4','5','6','7','8','9'); $a = new aclass; $a->b = new bclass; print_r(array_map(array(array($a, 'b') ,'foo'), $t)); Expected result: ---------------- Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 8 [4] => 10 [5] => 12 [6] => 14 [7] => 16 [8] => 18 ) Actual result: -------------- Warning: array_map(): The first argument, 'Array', should be either NULL or a valid callback in ...