|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-05-21 10:44 UTC] charles dot pick at gmail dot com
Description:
------------
At the moment there is no reliable way to determine whether a function is being
called statically or on an object directly. Sometimes it's useful to know the
difference between e.g.
foo::createUrl();
and
$foo->createUrl();
it would be nice to have a function, called something like is_static_call() which
could supply this information to the current method. I'm not familiar with the PHP
internals so I don't know how difficult this is to implement, but for me it would
be a useful feature.
Test script:
---------------
class foo {
public function createUrl($url = null, $params = array()) {
if ($url === null && is_static_call()) {
$url = "list";
}
elseif ($url === null) {
$url = "view";
}
/* do something */
}
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 01:00:01 2025 UTC |
It is already supported by checking if `$this` is set: class Foo { public function bar() { var_dump(isset($this)); } } Foo::bar(); // Prints bool(false) (new Foo())->bar(); // Prints bool(true) However calling non-static methods as stacic is not ok and will produce strict warnings.