[wp-hackers] looking for opinions on php5-only plugins

Silverstein, Jesse Jesse.Silverstein at xerox.com
Thu Oct 8 00:16:05 UTC 2009

Along these lines, is there an easy/safe way to check if a const
variable in a class will be accessed properly, versus throwing a fatal
error? It seems like some_method(ClassName::CONST_VAR); will throw a
fatal error in PHP 4 (I'm assuming because class constants are not
supported in 4). So, instead of checking for PHP version 5 or greater,
how would I check specifically for constant variable support?

-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Austin
Sent: Wednesday, October 07, 2009 5:56 PM
To: wp-hackers at lists.automattic.com
Subject: Re: [wp-hackers] looking for opinions on php5-only plugins

On Wed, Oct 7, 2009 at 12:49 PM, Otto <otto at ottodestruct.com> wrote:
> Version number checking is a bad idea. It's simply not accurate enough
> and doesn't tell you what you need to know.
> Checking for extensions, or functions provided by extensions (using
> function_exists or class_exists, etc) is much more accurate and sure
> to work. That's what I check for in the activation checks, whenever a
> plugin depends on something that somebody might not have.

I agree with the principle of checking behavior rather than version
number, and it's something I make a point of doing in JavaScript
especially (rather than depending on user-agent strings, for example).

However, to me what makes PHP 5 much better than PHP 4 is not
especially that PHP 5 has a few more functions like
timezone_offset_get(), but the syntactical differences: true private
methods, abstract classes, object interfaces, error handling, etc.
The trouble is that PHP 5-specific syntax won't even parse in PHP 4,
so I'm at a loss as how to alert PHP 4 users gracefully that my
WordPress plugin requires PHP 5.  I suppose I could check for the
existence of arbitrary PHP 5-only functions, but that runs the risk of
false positives thanks to something like wp-includes/compat.php or the
plugin equivalent.  And it, like version number checking, violates the
principle of checking for behavior.

So does anybody have any suggestions about a robust way to warn PHP 4
users that a WordPress plugin uses PHP 5 syntax?
wp-hackers mailing list
wp-hackers at lists.automattic.com

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.421 / Virus Database: 270.14.5/2418 - Release Date:
10/07/09 05:18:00

More information about the wp-hackers mailing list