Why does Eclipse object to `static :: $ var`?

I have the following static function in a PHP class:

static function __callStatic($method,$args){ $called=NULL; if(empty(static::$collection)) static::slurp(); if(method_exists(static::$objtype,$method)){ foreach(static::$collection as $obj){ $called[]= call_user_func_array(array($obj, $method), $args); } } else if (property_exists(static::$objtype,$method)){ //$method isn't a method, it a property foreach(static::$collection as $obj){ $called[]= $obj->$method; } } else if($method=='collection'){ $called=static::$collection; } else { throw new ZException("$method does not exist"); } return $called; } 

Static variables are defined, but may not have been set. It seems that the code does what I want and does not cause errors of any level. But still, my new installation of PDT Eclipse (Helios) marked every instance of static::$var as an "unexpected static" error. If I replace static::$var with self::$var , the Eclipse error will disappear, but then the code does not work.

How to convince Eclipse that these are not errors?

Eclipse for PHP developers Version: Helios Service Release 1 Build code: 20100917-0705 on 64-bit CentOS

+4
source share
2 answers

Late static binding appeared in PHP 5.3. Check Window> Preferences> PHP> Executables and Interpreter to make sure that Eclipse is using PHP 5.3.

enter image description here

+7
source

Using static:: was introduced in PHP 5.3.

I assume that Eclipse parses according to the rules of PHP 5.2. Either this, or his supervision, when they implemented the 5.3 rules in Eclipse.

Either way, you can update or fix Eclipse with the new ruleset to get it to parse the 5.3 syntax correctly.

+1
source

Source: https://habr.com/ru/post/1339216/


All Articles