php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43408 get_called_class not working as expected
Submitted: 2007-11-26 09:44 UTC Modified: 2008-04-07 11:03 UTC
From: bate@php.net Assigned: colder (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 6CVS-2007-11-26 (snap) OS:
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: bate@php.net
New email:
PHP Version: OS:

 

 [2007-11-26 09:44 UTC] bate@php.net
Description:
------------
The Function get_called_class works not as expected.
the new introduced static call works correct, the self call too but if you call the demo class with parent you dont get foo as result. This should be so because its not possible to overwrite a existing class in a  static class with late static binding.

get_called_class() should return in every call 'foo' and not as shown with parent::demo() a 'bar'



Reproduce code:
---------------
<?php
abstract class bar
{
    public static function demo()
    {
        var_dump(get_called_class());
    }
}

class foo extends bar
{
    public static function parent_demo()
    {
        parent::demo();
    }
    public static function self_demo()
    {
        self::demo();
    }
    public static function static_demo()
    {
        static::demo();
    }
}

echo 'bar::demo()' . PHP_EOL;
bar::demo();
echo 'foo::demo()' . PHP_EOL;
foo::demo();
echo 'foo::parent_demo()' . PHP_EOL;
foo::parent_demo();
echo 'foo::self_demo()' . PHP_EOL;
foo::self_demo();
echo 'foo::static_demo()' . PHP_EOL;
foo::static_demo();


?>

Expected result:
----------------
bar::demo()
string(3) "bar"
foo::demo()
string(3) "foo"
foo::parent_demo()
string(3) "bar"
foo::self_demo()
string(3) "foo"
foo::static_demo()
string(3) "foo"

Actual result:
--------------
bar::demo()
string(3) "bar"
foo::demo()
string(3) "foo"
foo::parent_demo()
string(3) "foo"
foo::self_demo()
string(3) "foo"
foo::static_demo()
string(3) "foo"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-12 10:36 UTC] tony2001@php.net
Assigned to the author of the LSB patch.
 [2007-12-12 17:42 UTC] colder@php.net
Fallbacks occur in static/self calls, as static/self resolve to "foo" and it returns foo as expected.

However, when you do a parent::demo() you actually call bar::demo(), which is currently understood as a "fully qualified call": the caller is not passed.

There are plans to allow explicit parent call to pass the caller, but this is still under discussion.
 [2007-12-12 17:46 UTC] bate@php.net
Hi Thanks for this comment so lets wait for a decision from the government. :)
 [2008-04-07 11:03 UTC] colder@php.net
In order to pass the caller information through a static call you'll now have to use a special function: forward_static_call() or forward_static_call_array()
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 05:01:29 2024 UTC