note 64233 deleted from language.oop5 by nlopess

From: Date: Tue, 18 Apr 2006 17:39:45 +0000
Subject: note 64233 deleted from language.oop5 by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-108421@lists.php.net to get a copy of this message
Note Submitter: Max Howell ---- If you need to run some code in a PHP 4 environment and a PHP 5 environment (for me, my test server is 4, my live server is 5), then you can use the following trick: <?php $keyword = version_compare( PHP_VERSION, '5.0.0', '>=' ) ? 'public' : 'var'; $eval_string = <<<END class Product { $keyword \$id; $keyword \$name; $keyword \$description; $keyword \$price; $keyword \$image_url; } END; eval( $eval_string ); unset( $keyword, $eval_string ); ?> Although, this is a little sucky for longer classes with many functions, so maybe someone could enhance this trick with an include or two?

« previous php.notes (#108421) next »