Problems with PHP 5.0.2 and OOP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Problems with PHP 5.0.2 and OOP

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

What does phpinfo() say?

PHP 5.0.x was crap ;) It only really started to get good at 5.1.x.
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Post 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();
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Post 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 :(
Post Reply