Bug #65466 [Opn->Ver]: forward_static_call doesn't trigger __callStatic for non-existing methods

From: Date: Wed, 16 Jul 2014 03:10:23 +0000
Subject: Bug #65466 [Opn->Ver]: forward_static_call doesn't trigger __callStatic for non-existing methods
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186656@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65466&edit=1

 ID:                 65466
 Updated by:         yohgaki@php.net
 Reported by:        daniel dot ruthardt at zoesolutions dot eu
 Summary:            forward_static_call doesn't trigger __callStatic for
                     non-existing methods
-Status:             Open
+Status:             Verified
 Type:               Bug
-Package:            Unknown/Other Function
+Package:            Scripting Engine problem
 Operating System:   Linux
 PHP Version:        5.4.18
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2013-08-17 14:13:13] 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 :-(


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=65466&edit=1


Thread (2 messages)

« previous php.bugs (#186656) next »