note 64233 added to language.oop5
| From: | MaxHowell at osu1 dot php dot net | Date: | Mon, 10 Apr 2006 13:19:39 +0000 |
| Subject: | note 64233 added to language.oop5 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107706@lists.php.net to get a copy of this message | ||
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?
----
Server IP: 85.116.0.130
Probable Submitter: 81.134.90.228
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.oop5.php
Edit -- http://master.php.net/note/edit/64233
Del: integrated -- http://master.php.net/note/delete/64233/integrated
Del: useless -- http://master.php.net/note/delete/64233/useless
Del: bad code -- http://master.php.net/note/delete/64233/bad+code
Del: spam -- http://master.php.net/note/delete/64233/spam
Del: non-english -- http://master.php.net/note/delete/64233/non-english
Del: in docs -- http://master.php.net/note/delete/64233/in+docs
Del: other reasons-- http://master.php.net/note/delete/64233
Reject -- http://master.php.net/note/reject/64233
Search -- http://master.php.net/manage/user-notes.php