Page 1 of 1

Problems with PHP 5.0.2 and OOP

Posted: Mon Mar 19, 2007 11:48 am
by Kadanis
Hi

I'm working on a site for a client who uses Lycos.co.uk for their webhosting. Lycos claims that they have PHP 5.0.2 installed on their servers, and to use PHP5 you just have to name your scripts with a .php5 extension.

I'm trying to run a class with protected and private vars, preset vars etc common to OOP in PHP5.

Code: Select all

class Foo{
 protected $foo = 'bar';

 private $bar = 'foo';

 public function __construct(){
    #do something
 }
}
However, the errors I get when I run the page are due to the protected / private keywords and the assignment outside a function. Googling them say the cause is running PHP5 on a PHP4 enabled server.

My question is, when did the OOP constructs like private / protected / public etc actually come in to PHP. Was it with the first release of 5 or was it a later version i.e 5.1 or even 5.0.3 for example...?

Thanks in advance

Posted: Mon Mar 19, 2007 12:04 pm
by Chris Corbyn
What does phpinfo() say?

PHP 5.0.x was crap ;) It only really started to get good at 5.1.x.

Posted: Mon Mar 19, 2007 12:07 pm
by Kadanis
To be honest, I don't know exactly what I'm looking for in the phpinfo() when I comes to the OOP stuff.

Don't know if its wise to post a link to it either, but maybe I'm just being over cautious. Is there is anything in particular I should look for?

Thanks

Posted: Mon Mar 19, 2007 12:09 pm
by Chris Corbyn
I just meant does it reveal to be 5.0 or 4.x? 5.0 did support private, protected etc.... that's why it was crap. They got all giddy and excited and decided it was fatally wrong to use "var" under E_ALL. That sounds changed when people reacted badly.

Posted: Mon Mar 19, 2007 12:12 pm
by Kadanis
Ah, I see.

Just noticed this at the top, don't know exactly what it means but sounds ominous
PHP4u Version 3.0
Based on PHP-5.0.2
As for the var thing. I'm using protected rather than var on all the variables. The error message is something like

parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' on line 17 of cls.templater.php5
line 17 of cls.templater.php5 is

Code: Select all

protected $variables = array();

Posted: Mon Mar 19, 2007 12:16 pm
by Chris Corbyn
Looks like some kind of patched/hacked version of PHP :?

It's definitely *not* PHP5 if it's giving that error. Who's hosting the server? Ask them to upgrade/fix PHP ;)

Posted: Mon Mar 19, 2007 12:20 pm
by Kadanis
The webhost is Lycos. I thought they would be relatively respectable. Looks like they've done some weird hack then.

As soon as I removed all the public / private from the functions. The variables redefined as var, and removed the try catch statments, the whole thing worked.

Just looks like a PHP4 script now, though :(