how to check for a static call from an object
| From: | Sebastian Mendel | Date: | Thu, 21 Jul 2005 09:16:47 +0000 |
| Subject: | how to check for a static call from an object | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-219095@lists.php.net to get a copy of this message | ||
Hi,
how can i check if a method is called statically when called from inside
another object? (without debug_bactrace())
class foo
{
function bar()
{
if ( isset( $this ) )
{
return 'not static';
}
return 'static';
}
function bar2() { foo::bar(); }
}
// returns 'not static'
echo foo::bar();
// returns 'static' but should be 'not static'
$foo = new foo;
echo $foo->bar2();
so, how can i prevent a method from called static or not called static?
and btw. does anynone know why it is not good to let one function handle
both mehtods of calling (static and not static) as in PHP 5 you will get
notices if called wrong - but PHP doesnt support multiple
function-definitions like:
class foo
{
static function bar()
{
return ANY_DEFAULT_VALUE;
}
function bar()
{
return $this->value;
}
}
or even
class foo
{
static function bar( $param )
{
return $param;
}
function bar()
{
return $this->param;
}
}
or is this at least an issue for the internals-list?
--
Sebastian Mendel
www.sebastianmendel.de
www.sf.net/projects/phpdatetime | www.sf.net/projects/phptimesheet