php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53742 Late static binding does not work via reflection
Submitted: 2011-01-13 21:22 UTC Modified: 2011-12-21 07:13 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:0 (0.0%)
From: blue-tidus159 at hotmail dot com Assigned: laruence (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: Irrelevant OS: Windows 7 x64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: blue-tidus159 at hotmail dot com
New email:
PHP Version: OS:

 

 [2011-01-13 21:22 UTC] 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() 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-12 20:06 UTC] 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-08-04 19:13 UTC] josh at joshbutts dot com
Still exists in PHP 5.3.5. Reproducible with the script above.
 [2011-12-21 07:02 UTC] will dot fitch at gmail dot com
This is fixed in 5.4 and HEAD:

Fatal error: Class A contains 1 abstract method and must therefore be declared 
abstract or implement the remaining methods (A::callLate)
 [2011-12-21 07:13 UTC] laruence@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: laruence
 [2011-12-21 07:13 UTC] laruence@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

dup to #60367
 [2013-04-03 20:28 UTC] david at orlandophp dot org
Any chance this will get back-ported into older versions? It's still broken in 
PHP 5.3.x up until 5.3.8, which represents a widely distributed range of 
versions.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 09:01:30 2024 UTC