From:             ms419 at freezone dot co dot uk
Operating system: 
PHP version:      5.2.5
PHP Bug Type:     Feature/Change Request
Bug description:  Function can no longer be called both statically and as 
instance method

Description:
------------
I understand that, unlike some other languages, PHP does not support
overloading: I can't implement two functions with the same name but
different signatures. However I can simulate overloading using
func_get_args() and testing with which arguments the function was called.

Now what I want is a function which can be called either as an instance
method with no arguments, or statically with one argument: an instance of
the class. I test whether the function was called statically or not using
isset($this)

However in PHP5, this produces an error:

Non-static method BaseTaxonomy::getTerms() should not be called statically
in...

Like it is possible to simulate overloading in PHP without generating
errors, I wish it were possible to define a function which can be called
either statically or as an instance method, without generating errors.

Much thanks, Jack

Reproduce code:
---------------
Toy example:

class BaseTaxonomy
{
  protected $terms = null;

  public function getTerms()
  {
    if (!isset($this))
    {
      $args = func_get_args();

      return $args[0]->terms;
    }

    return $this->terms;
  }
}

Actual result:
--------------
Non-static method BaseTaxonomy::getTerms() should not be called statically
in...

-- 
Edit bug report at http://bugs.php.net/?id=43845&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43845&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43845&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43845&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43845&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43845&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43845&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43845&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43845&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43845&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43845&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43845&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43845&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43845&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43845&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43845&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43845&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43845&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43845&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43845&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43845&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43845&r=mysqlcfg

Reply via email to