Edit report at https://bugs.php.net/bug.php?id=53742&edit=1

 ID:                 53742
 Comment by:         josh at joshbutts dot com
 Reported by:        blue-tidus159 at hotmail dot com
 Summary:            Late static binding does not work via reflection
 Status:             Open
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Windows 7 x64
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Still exists in PHP 5.3.5. Reproducible with the script above.


Previous Comments:
------------------------------------------------------------------------
[2011-05-12 20:06:23] phdaemon at gmail dot com

I experienced this bug when building a new automation framework using PHPUnit + 
selenium.

IT seems that PHPUnit uses reflection to instantiate a static function called 
suite which handles an array of browsers and duplicating a testcase to run in 
each one.

I was on the latest ubuntu package: PHP 5.3.3-1ubuntu9.5 with Suhosin-Patch 
(cli) (built: May  3 2011 00:49:55) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies


I got around it by switching the reflection to call_user_func but this should 
probably be fixed as PHPUnit is very popular.

------------------------------------------------------------------------
[2011-01-13 21:22:52] blue-tidus159 at hotmail dot com

Description:
------------
When a static method is called through reflection, late static binding does not 
work. Probably because the getMethod() returns the method associated to the 
parent class.

Test script:
---------------
class A{
  public static function call(){
    static::callLate();
  }

  public static abstract function callLate();
}

class B{
  public static function callLate(){
    echo 'Late static binding';
  }
}

B::call();
$class = new ReflectionClass('B');
$class->getMethod('call')->invoke(null);

Expected result:
----------------
Late static binding
Late static binding

Actual result:
--------------
Late static binding
Cannot call abstract method B::callLate() 


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=53742&edit=1

Reply via email to