Bug #72916 [NEW]: get_called_class is wrong after calling via self:: from non-static method

From: Date: Sun, 21 Aug 2016 23:18:23 +0000
Subject: Bug #72916 [NEW]: get_called_class is wrong after calling via self:: from non-static method
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203467@lists.php.net to get a copy of this message
From:             gharlan at web dot de
Operating system: 
PHP version:      7.0.10
Package:          Class/Object related
Bug Type:         Bug
Bug description:get_called_class is wrong after calling via self:: from non-static method

Description:
------------
The return value of get_called_class() is wrong, when it is called from
a static method that is called via self::method() in a non-static
method.

Test script:
---------------
<?php
class Foo {
    protected static function getClass() {
        return get_called_class();
    }
    
    public function bar() {
        echo 'Foo: ', Foo::getClass(), "\n";
        echo 'self: ', self::getClass(), "\n";
        echo 'static: ', static::getClass(), "\n";
    }
}

class Child extends Foo {
    protected static function getClass() {
        return 'x';
    }
}

(new Child)->bar();

Expected result:
----------------
Foo: Foo
self: Foo
static: x

Actual result:
--------------
Foo: Foo
self: Child
static: x

-- 
Edit bug report at https://bugs.php.net/bug.php?id=72916&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72916&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72916&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72916&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72916&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72916&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72916&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72916&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72916&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72916&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72916&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72916&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72916&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72916&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72916&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72916&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72916&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72916&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72916&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72916&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72916&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#203467) next »