php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67620 is_callable and self
Submitted: 2014-07-15 08:35 UTC Modified: 2021-10-20 13:14 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: remyfox at hotmail dot com Assigned: cmb (profile)
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.4Git-2014-07-15 (Git) OS: windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
44 + 32 = ?
Subscribe to this entry?

 
 [2014-07-15 08:35 UTC] remyfox at hotmail dot com
Description:
------------
PHP 5.4.7

When "self" is provided to is_callable, while inside a class that doesn't contain the method nor has a parent with the method, it will behave as $this.

Subsequent calling of the method which had been falsely declared callable, will result in 

Fatal error: Call to undefined method A::y() in *__FILE__* on line 5

Test script:
---------------
<?php
	class A {
		public function x() {
			if (is_callable(array($this, "y"))) $this::y();
			if (is_callable(array("self", "y"))) self::y();
		}
	}
	
	class B extends A {
		public function y() {}
	}
	
	(new B())->x();
?>

Expected result:
----------------
Self should behalve like __CLASS__ in the example above and the fatal error should be avoided.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-15 13:08 UTC] danack@php.net
-Assigned To: +Assigned To: danack
 [2016-01-15 13:08 UTC] danack@php.net
Assigning to myself. This will require an RFC to change.

https://wiki.php.net/rfc/consistent_callables
 [2021-10-20 13:14 UTC] cmb@php.net
-Status: Assigned +Status: Wont fix -Package: Unknown/Other Function +Package: Scripting Engine problem -Assigned To: danack +Assigned To: cmb
 [2021-10-20 13:14 UTC] cmb@php.net
Use self::class instead of "self"[1].  Also note that there is an
RFC in voting which proposes to deprecate this callable syntax[2],
and it is highly likely that it will pass, so I'm closing this
ticket as WONTFIX.

Also note that that self is sloppy here, and that it should be
static instead.  Then, as of PHP 8.1.0, you can use the first
class callable syntax[3].

[1] <https://3v4l.org/U6KEk>
[2] <https://wiki.php.net/rfc/deprecate_partially_supported_callables>
[3] <https://3v4l.org/QnPHB>
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Aug 18 16:05:45 2022 UTC