From:             a at b dot c dot de
Operating system: Windows XP SP2
PHP version:      5.2.0
PHP Bug Type:     Feature/Change Request
Bug description:  Repeated dereferencing in object callbacks

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 ...


-- 
Edit bug report at http://bugs.php.net/?id=40061&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=40061&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=40061&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=40061&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=40061&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=40061&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=40061&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=40061&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=40061&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=40061&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=40061&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=40061&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=40061&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=40061&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=40061&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=40061&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=40061&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=40061&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=40061&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=40061&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=40061&r=mysqlcfg

Reply via email to