why is Eclipse objecting to `static::$var`? - php

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's 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;
}
The static variables are all defined but possibly not set. The code appears to do what I want it to and throws no errors of any level. But yet my new installation of Eclipse (Helios) PDT has marked every instance of static::$var as an 'unexpected static' error. If I replace static::$var with self::$var the Eclipse error goes away- but then the code doesn't work.
How do I convince Eclipse that these are not errors?
Eclipse for PHP Developers
Version: Helios Service Release 1
Build id: 20100917-0705
on 64 bit CentOS

Late Static Binding was introduced with PHP 5.3. Check Window > Preferences > PHP > Executables and Interpreter to make sure Eclipse is using PHP 5.3.

The use of static:: was introduced in PHP 5.3.
My guess would be that Eclipse is parsing according to PHP 5.2 rules. Either that, or its an oversight when they implemented the 5.3 rules in Eclipse.
Either way, you may be able to upgrade or patch Eclipse with a new rule set to get it to parse 5.3 syntax correctly.

Related

Phppgadmin, No objects found

I am trying to get my localhost db listed in phpPgAdmin, but it says No object found phppgadmin GUI
I have already configured conf/config.inc
$conf['servers'][0]['desc'] = 'PostgreSQL'
$conf['servers'][0]['host'] = 'localhost';
$conf['servers'][0]['port'] = 5432;
$conf['owned_only'] = false;
Any help please, I have tried with Postgresql versions 9.2,9.5,10.3(not supported by phppgadmin?)
EXPLANATION OF THE PROBLEM
I see the problem! This error message is a bug in the phpPgAdmin code, which apparently has older code that was written before PHP 7.x was released.
The error in phpPgAdmin will appear if you've recently downloaded a technology stack with all of the latest versions of PHP, PostGreSQL and phpPgAdmin. For example... today's (Feb. 2019) latest versions are:
PHP 7.3.1
PostGreSQL version 11
phpPgAdmin 5.6 (Nov. 12, 2018) <= This doesn't work with PHP 7.x, but we want it to work with it and we can make it work with it!
PHP.net explains the problem in their Constructors and Destructors page:
Warning Old style constructors are DEPRECATED in PHP 7.0, and will be
removed in a future version. You should always use __construct() in
new code.
Their example is in this section on that page:
Example #2 Constructors in namespaced classes
<?php
namespace Foo;
class Bar {
public function Bar() { <- This is an older style of creating a constructor.
For PHP 7.x, it should be changed to "__construct" instead of "Bar".
// treated as constructor in PHP 5.3.0-5.3.2
// treated as regular method as of PHP 5.3.3
}
}
?>
Now that we know what the problem is, here is how to solve it.
SOLUTION
Look in your /phpPgAdmin/ folder on your web server. You should find the following files in the /classes/ sub-folder:
ArrayRecordSet.php <- Replace function ArrayRecordSet with function __construct
class.select.php <- Replace function XHtmlSimpleElement with function __construct
Gui.php <- Replace function GUI with function __construct
Misc.php <- Replace function Misc() with function __construct
Plugin.php <- Already has function __construct
PluginManager.php <- Already has function __construct
Edit those files & change any of the constructor names - which appear as duplicate class names - to __construct.
When you save those files & reload phpPgAdmin in your browser, then you will see that the "No objects found" message will have disappeared. It will then display a server name.
VoilĂ ! The latest version of phpPgAdmin 5.6 works with the latest version of PHP 7.3.1 & the latest version of PostGreSQL 11!
If you want to check the XML contents of that left tree, simply append this to your website as this is the rest of the URL, which it's using: /phppgadmin/servers.php?action=tree. That will help make debugging the phpPgAdmin code easier to do.
You can also remove the action=tree querystring parameter. Or search for it inside of the phpMyAdmin code.
BUG REPORT
I'll see about submitting a phpPgAdmin bug report to with the link to this page. Hopefully, someone will fix this error in the phpPgAdmin code base.
Have fun using the latest version of phpPgAdmin, PHP & PostGreSQL!

Aptana Studio 3 stand alone version will not reconize php 7.1.3 syntax in linux

Even after I added the php 7.1.3 executable to my version of AptanaStudio 3, it still will not reconize my script which uses a method with a return type declaration. Aptana seems to only recognize loosely typed method definition syntax like what is used in php 5.6.
How can I get Aptana Studio to recognize my newer version of php (7.1.3)?
public function get_name (string $name): string
{
$this->$name = $name;
return $this->name;
}
The above code is an example of code that produces an error in my AptanaStudio 3 IDE. However, when I run the code from my browser using my apache server, it runs like a charm.
Could anyone tell me what I am doing wrong?

Can PHP Traits be disabled in 5.4.x?

I have a client using Rackspace Cloud Sites which advertise PHP 5.4 on their platform but I have been advised via their online support that traits cannot be used.
When using traits I receive a 500 error and finding no issue with the code I asked their online support to be told "it is not allowed in our environment". Using the basic PHP example code below results in a 500 Internal Server Error:
class Base {
public function sayHello() {
echo 'Hello ';
}
}
trait SayWorld {
public function sayHello() {
parent::sayHello();
echo 'World!';
}
}
class MyHelloWorld extends Base {
use SayWorld;
}
$o = new MyHelloWorld();
$o->sayHello();
Is there some reason why Traits would be disabled or can they even be disabled? The version reported by phpinfo() is 5.4.10.
After some discussions with rackspace support it seems the issue is with xcache and execution of some items such as traits. Adding the following line to .htaccess resolves the issue:
php_flag xcache.cacher 0
Seems it is not a rackspace issue but an xcache issue.
Php traits cannot be disabled. If you have a limited use of traits, you could comment out the "use" statements.

PHPExcel not working php 5.2 AppServ

I am using php 5.2.6 in AppServ on a Windows machine and PHPExcel does not seem to work and produces no errors. I have error_reporting set to E_ALL.
On my Linux machine where I am using php 5.6 and using vagrant/homestead the same code works just fine.
Here is my code:
http://pastebin.com/6dJC8gaP
I added some echos to see where exactly it dies, and it seems to die on line 9. I had thought maybe it was an issue with php 5.2 and :: referencing, so I tried using the call_user_func, which also works on my php 5.6 but does not work on my php 5.2
http://php.net/manual/en/function.call-user-func.php
<?php
namespace Foobar;
class Foo {
static public function test() {
print "Hello world!\n";
}
}
call_user_func(__NAMESPACE__ .'\Foo::test'); // As of PHP 5.3.0
call_user_func(array(__NAMESPACE__ .'\Foo', 'test')); // As of PHP 5.3.0
?>
Per page:
Quote:
In PHP v5.2, you /can/ use call_user_func(array($this, 'parent::SOME_FUNCTION')).
If you don't have custom __autoload() function, you are good to go.
If you do have custom __autoload(), you need to make it `parent' aware. Something like:
Rationale: PHP 5.2 surprisingly tries to autoload a class named 'parent'. However, if you don't do anything in __autoload() for the 'parent' class, it'll work just fine.
In PHPExcel/Settings.php there are two references to libxml_disable_entity_loader function.
That function is not available until php 5.2.11, and the # in front of it was causing a silent error.
I did as they suggested and wrapped that function in function_exist checks. Everything works fine now.
Reference: https://github.com/PHPOffice/PHPExcel/issues/339

PHP 5.3 vs 5.4 : 'this' showing up as undefined variable in object

I'm having issues with code that worked fine in PHP 5.3 and is now broken in PHP 5.4. The original environments where the code works are:
Ubuntu 11.04
Lighttpd 1.4.29
PHP 5.3
and
Mac OSX 10.7.4
Apache 2.0.63
PHP 5.3
and the new environment is:
Android 4.0.4
Lighttpd 1.4.29
PHP 5.4.4
I've boiled down the problem code to two simple files:
[test.class.php]
class Test {
public $testProp1;
function setTestProp1($value){
$this->testProp1 = $value;
return ($this->testProp1 != '') ? true : false;
}
function doSomething()
{
if( $this->testProp1 )
{ echo "Just do some " . $this->testProp1; }
else
{ echo "Just do nothing"; }
}
}
[debug.php]
error_reporting(E_ALL);
require "test.class.php";
$myTest = new Test();
$myTest->setTestProp1("foo");
$myTest->doSomething();
On the system with PHP 5.3, the output is:
Just do some foo
On the system with PHP 5.4, the output is:
Warning: Creating default object from empty value in /data/www/test.class.php on line 5
Notice: Undefined variable: this in /data/www/test.class.php on line 11
Notice: Trying to get property of non-object in /data/www/test.class.php on line 11
Just do nothing
Even if I change the error reporting level, I still get the warning and 'Just do nothing' in PHP 5.4. Not sure what the deal is, I'm totally stumped. Any help is appreciated!
Tried this on another install of PHP 5.4.4 on Mac OSX and it worked fine. We're thinking something went wrong when we ported PHP to Android so we'll have to revisit that process. In the future will definitely test more configurations before posting on SO.
Thanks everyone.

Categories