php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65466 forward_static_call doesn't trigger __callStatic for non-existing methods
Submitted: 2013-08-17 14:13 UTC Modified: 2014-07-16 03:10 UTC
From: daniel dot ruthardt at zoesolutions dot eu Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: 5.4.18 OS: Linux
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: daniel dot ruthardt at zoesolutions dot eu
New email:
PHP Version: OS:

 

 [2013-08-17 14:13 UTC] daniel dot ruthardt at zoesolutions dot eu
Description:
------------
---
From manual page: http://www.php.net/function.forward-static-call
---

The manual page makes you think that this function can be used to force a static method 
call, it however doesn't. Essentially, this functions just does the same thing as does 
the :: operator, which heavily depends on the current context - as unfortunately does 
forward_static_call.

One might expect, that using a function which says in its name and description, that it 
will call static methods, that calling non-existing static methods will end up in 
__callStatic and not in __call.

Test script:
---------------
<?php

class A {

	public function __call($name, $arguments) {
		echo("i don't want to be in here :-(");
	}

	public static function __callStatic($name, $arguments) {
		echo('i want to be in here, but how?');
	}

	public function instanceMethod() {
		// objective: call a non-existing static method,
		// so that eventually __callStatic is called and
		// can take care of things
		forward_static_call(['A', 'test']);
	}

}

(new A())->instanceMethod();

?>

Expected result:
----------------
i want to be in here, but how?

Actual result:
--------------
i don't want to be in here :-(

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-16 03:10 UTC] yohgaki@php.net
-Status: Open +Status: Verified -Package: Unknown/Other Function +Package: Scripting Engine problem
 [2014-07-16 03:10 UTC] yohgaki@php.net
http://3v4l.org/9kcSk

PHP does not call __callStatic() when it's in the same class.
forward_static_call() should call it's own __callStatic()?

<?php
class A
{
    const NAME = 'A';
    public function __call($name, $args) {
        echo 'Non-Static ' . static::NAME . ' ' . $name;
    }

    public static function __callStatic($name, $args) {
        echo 'Static ' . static::NAME . ' ' . $name;
    }

}

class B extends A
{
    const NAME = 'B';

    public static function test() {
        echo self::NAME, "\n";
        forward_static_call(array('A', 'notExist'), 'more', 'args');
    }
}

B::test('foo');
?>

outputs

B
Static B notExist
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC