|
Posted by Mateusz Markowski on 09/19/06 07:52
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.
Navigation:
[Reply to this message]
|