You are here: Re: Checking PHP version for compatibility? « PHP Programming Language « IT news, forums, messages
Re: Checking PHP version for compatibility?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация