[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-doc-bugs
Subject:    [DOC-BUGS] [PHP-BUG] Doc #75530 [NEW]: __callStatic precedence in non-static method invocation
From:       "msaladna at apisnetworks dot com"<php-bugs () lists ! php ! net>
Date:       2017-11-15 21:48:54
Message-ID: bug-75530 () bugs ! php ! net
[Download RAW message or body]

From:             msaladna at apisnetworks dot com
Operating system: Irrelevant
PHP version:      7.1.11
Package:          Class/Object related
Bug Type:         Documentation Problem
Bug description:__callStatic precedence in non-static method invocation

Description:
------------
According to the documentation, 
__callStatic() is triggered when invoking inaccessible methods in a
static context.

If a method then is declared non-static with a __callStatic() handler in
the class, accessing the method statically should route through
__callStatic() instead of generating a fatal error as the method is
inaccessible statically.

Test script:
---------------
<?php
	class Test
	{
		protected $root = '';

		public function __construct(string $root = '/')
		{
			$this->root = $root;
		}

		public static function bindTo(string $root = '/')
		{
			return new static($root);
		}

		public static function __callStatic($name, $arguments)
		{
			$instance = static::bindTo();
			return $instance->$name($arguments);
		}

		public function test() {
			return $this->root . '/foo';
		}
	}

	print Test::bindTo('/elsewhere')->test();
	print Test::test();

Expected result:
----------------
/elsewhere/foo
/foo

Actual result:
--------------
/elsewhere/foo
PHP Fatal error:  Uncaught Error: Non-static method Test::test() cannot
be called statically

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


-- 
PHP Documentation Bugs Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic