how to check for a static call from an object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux