|
Posted by Colin Fine on 09/24/06 09:23
Mateusz Markowski wrote:
> rustysmith@bellsouth.net napisal(a):
>> Anyone know how to check the PHP version that a current file is
>> running on? This would be helpful in the instance where you are trying
>> to make a package that can be distributed publicly for use in a variety
>> of configurations. This code should(?) work:
>>
>> $ver=PHP_VERSION;
>> if(ereg('^[1-4]',$ver))
>> $post_ids=array_flip(&$post_ids); // Old syntax
>> else
>> $post_ids=array_flip($post_ids); // PHP 5+ syntax
>>
>
> For version comapring you should write:
>
> if (version_compare(phpversion(), '4.0.0', '>='))
> //version above 4.0.0
> else
> //version below 4.0.0
>
> But it won't work in a way you want. For example:
> <?php
>
> if (version_compare(phpversion(), '5.0.0', '>=')){
> //PHP5
> class Foo{
> private $foobar;
> public function __construct(){
> echo 'Foo';
> }
> }
> }else{
> //PHP5
> class Foo{
> var $foobar;
> function Foo(){
> echo 'Foo';
> }
> }
> }
> ?>
> The PHP4's parser will give you a parse error.
> If you want to be compatibile with both versions, just write in PHP4.
>
But then you have to turn NOTICES off (not necessarily in this case, but
in some incompatibilities).
I've ended up taking my own copy of PEAR::Date and editing it to declare
all the static functions as static in order to use it in PHP5 without
notices.
I can't believe this is the right way to deal with the problem, but I
don't know what else to do.
Colin
[Back to original message]
|