From: Operating system: PHP version: Irrelevant Package: Unknown/Other Function Bug Type: Feature/Change Request Bug description:Allow class methods to determine whether they're being called statically or not
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 */ } } -- Edit bug report at http://bugs.php.net/bug.php?id=54897&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54897&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54897&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54897&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54897&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54897&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54897&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54897&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54897&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54897&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54897&r=support Expected behavior: http://bugs.php.net/fix.php?id=54897&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54897&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54897&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54897&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54897&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54897&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54897&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54897&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54897&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54897&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54897&r=mysqlcfg