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
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
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
 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 03 21:01:27 2024 UTC