Reply to Re: Checking PHP version for compatibility?

Your name:

Reply:


Posted by Jerry Stuckle on 09/24/06 13:02

Colin Fine wrote:
> 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

Maybe put the level-specific code in two different files and include the
appropriate file based on the PHP version?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original 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

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