Var in PHP 5 question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all,
I've written a large system for PHP4 that declares class variables
using the 'var' keyword. I'm now upgrading to PHP5, and it seems I have
to change 'var' to private / public / protected, which don't work in
PHP4. Is there anyway to make my system compatible with both versions?


Re: Var in PHP 5 question wrote:
Quoted text here. Click to load it

The var keyword is supported in PHP5, albeit deprecated. If you want your  
code to be both backwards compatible and take advantage of PHP5's  
declaration style, the best thing you can do is to write classes for both  
versions and apply them conditionally:

if (PHP_VERSION < 5) {
    include "php4class.php";
} else {
    include "php5class.php";

$obj = new MyClass;


Re: Var in PHP 5 question

In PHP 5 this is reported as a warning, not an error, so it will still run  
OK. I know because I have encountered the same situation with code that I  
use which needs to run under both PHP 4 and PHP 5.

Tony Marston

Quoted text here. Click to load it

Site Timeline