php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77618 get_class_function() reports wrong class name in parent:: context
Submitted: 2019-02-14 09:03 UTC Modified: 2019-02-14 09:08 UTC
From: llmll at gmx dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 7.2.15 OS: All
Private report: No CVE-ID: None
 [2019-02-14 09:03 UTC] llmll at gmx dot de
Description:
------------
The function get_class_function() should always return the class name of the context in which it is called. Dynamic or Static context should make no difference.

When wrapped in a parent:: call it returns the child's class name not the parent's one.

Test script:
---------------
class A {
	public static function Name() {
		return get_called_class();
	} 
}
class B extends A {
	public static function NameOfParent() {
		return parent::Name();
	}
}

echo B::Name();
echo B::NameOfParent();

Expected result:
----------------
should report "B" as Name() and "A" as NameOfParent().

Actual result:
--------------
return "B" twice, because parent doesn't change the context from B:: to A:: as it should.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-14 09:08 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2019-02-14 09:08 UTC] krakjoe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

In both cases, the name of the called class is B:

echo B::Name();
echo B::NameOfParent();
 [2019-02-17 18:28 UTC] llmll at gmx dot de
And that ist wrong! Dont care what documentation says.
 [2019-02-17 18:30 UTC] llmll at gmx dot de
static::Name() should return "B"

BUT

parent::Name() must return "A"
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC