is_a instanceof and get_class

One of the more common errors thrown by the WordPress Core files are the E_STRICT errors:

is_a(): Deprecated. Please use the instanceof operator

These errors are somewhat unique. The instanceof operator was not introduced until PHP version 5.0 and as of version 5.3 is_a is no longer deprecated. Since is_a works in all PHP versions >= 4.2 (and in fact, in some versions instanceof can throw a fatal error), should these errors simply be ignored?

Other than keeping these errors from cluttering up error logs when error reporting is configured to include them, might there be a good reason for changing the WordPress files to use instanceof instead? Does an error being thrown slow things down even when error reporting is off?

To test this, I put together a simple benchmark script and ran several variations of it. In all tests I turned off display errors, created an emptyClass, assigned an istance of that class to a variable, set an iteration variable to 4400000 (4 million 400 thousand), and initialized some variables to hold the conditional tests' results. I then created 2 test blocks, one with error reporting on, the other off. In each of these were 3 test blocks where the time limit was set to 120 seconds, microtime was assigned to a start variable, a for loop with a conditional test was used, microtime was assigned to a stop variable, start time subtracted from stop time, and the resulting values displayed to the screen.

I used 3 conditional tests in ternary form, in most tests using a variable to hold the string "emptyClass" and assigning either the string "true" or "false". But in other tests, I used the string in the conditional [test runs 5,6], and in the last assigned boolean true or false [test run 6]. In some tests I assigned a different emptyClass to "foo" [test runs 3,4]. I also changed the sequence of the error reporting "on" and "off" blocks a few times.

The conditional tests used were:
$isa = (is_a($foo, 'emptyClass')) ? true : false;
$iof = ($foo instanceof emptyClass) ? true : false;
$gc = (get_class($foo) == 'emptyClass') ? true : false;

The results were:
isa: true isa_off_run_time: 100.178678036
isa: true isa_off_run_time: 99.1540658474
isa: false isa_off_run_time: 99.960310936
isa: false isa_off_run_time: 103.339380026
isa: true isa_off_run_time: 106.143660069
isa: 1 isa_off_run_time: 105.840899944

iof: true iof_off_run_time: 35.3434741497
iof: true iof_off_run_time: 35.5949220657
iof: false iof_off_run_time: 35.5492649078
iof: false iof_off_run_time: 35.5479259491
iof: true iof_off_run_time: 34.432945013
iof: 1 iof_off_run_time: 33.126625061

gc: true gc_off_run_time: 33.4457361698
gc: true gc_off_run_time: 33.5602648258
gc: false gc_off_run_time: 33.3188569546
gc: false gc_off_run_time: 34.7413768768
gc: true gc_off_run_time: 33.0190939903
gc: 1 gc_off_run_time: 31.8450849056

isa: true isa_on_run_time: 102.209348202
isa: true isa_on_run_time: 102.416124105
isa: false isa_on_run_time: 100.420098066
isa: false isa_on_run_time: 102.395892143
isa: true isa_on_run_time: 106.603455782
isa: 1 isa_on_run_time: 104.104444027

iof: true iof_on_run_time: 35.7016470432
iof: true iof_on_run_time: 35.5722339153
iof: false iof_on_run_time: 35.5262870789
iof: false iof_on_run_time: 35.2299501896
iof: true iof_on_run_time: 34.4370470047
iof: 1 iof_on_run_time: 32.9595680237

gc: true gc_on_run_time: 33.9093399048
gc: true gc_on_run_time: 33.8212268353
gc: false gc_on_run_time: 33.8323700428
gc: false gc_on_run_time: 33.9559469223
gc: true gc_on_run_time: 32.9235389233
gc: 1 gc_on_run_time: 31.7332019806

As can be seen, I found no appreciable difference between the error reporting off and error reporting on run times. However, is_a takes roughly 3 times as long as instanceof, and get_class is somewhat faster than instanceof.

Does this matter? Some files that call is_a run only very seldom, and some may not get called at all depending on your blog set up and your blogging habits. But, as we shall see, at other times is_a is called many times.

These tests provide only a very limited result set. Because of variations due to other running system processes, and the changes made to the script between test runs, they should be interpreted with caution. If you care to, you should run similar tests on your own server with your version of PHP.

Although the error message suggests using the instanceof operator insread of is_a, the instanceof operator was not introduced until PHP version 5.0, and as mentioned, in some cases can throw a fatal error. get_class however, was introduced in PHP version 4.0 and also appears to have the fastest run time of the 3 conditionals, even if it is slightly more verbose.

I have left a comment regarding this on the Trac ticket core.trac.wordpress.org/ticket/10264

Technorati Tags: ,

WordPress Functions 2.8

WordPress version 2.8 brings quite a few changes, including the use of SimplePie and a new Widgets API. The plugin searched 242 PHP files (17 more than 2.7), of which 155 contained classes and functions (13 more than 2.7), and found 107 classes (36 more than 2.7) and 2,944 functions. This is 568 more functions than were found in WordPress version 2.7

It seems the WordPress Core grows with every release.

The PHP Classes and Functions of WordPress 2.8

* Note *
The list does not include any found in plugin or theme files as these will differ from blog to blog. Nor does it differentiate between "stand alone" functions and functions that are members of a class, such as the Snoopy functions.

If you know of any functions that are not in the list, please leave a comment so I can modify the regex used to find them.

Technorati Tags: ,

Too Many Errors in 2.8

After upgrading to WordPress version 2.8, I discovered that my Error Reporting Plugin was causing Internal Server Errors for requests to the blog's front pages. After much investigating and testing, I have determined the cause being an extreme number of PHP errors in the Core files. Because the Error Reporting plugin uses eval to test errors against a configurable conditional test every error, the repeated use of eval over-taxed the server.

I was finally able to pinpoint the cause of the problem by temporarily eliminating the eval and having the plugin display all errors on screen. My apologies to those that visited during this phase of the testing.

I have submitted Trac tickets for some of these errors, but I do not know when or if they will be fixed.

I will publish further details in following posts in this category.

Technorati Tags: ,

Clean Options Translations

Please Donate. No, I don't want your money.

But if you are bilingual and fluent in English and another language, I will appreciate your help in providing translations. Beginning with version 1.2.0 the Clean Options plugin has a POT file in it's languages folder.

I can create the MO files, what I need is the language_Country PO files, or at least the translations of the various text strings so that I can create cleanoptions-ll_CC.po files using the translated text.

To avoid duplication of effort, please check here to make sure the particular language_Country translation isn’t already done or in progress.

I will edit this post by adding a list of the translations here so you won’t need to read all the comments.

Current Translations

  • es_ES Samuel . . . . . in progress
  • ru_RU onix . . . . . in progress
  • uk_UA onix . . . . . in progress??

Please leave a comment so I will know that you’re helping me and I can add you to the list. Many Thanks

Google sitemap.xml Validation

There are several ways to validate a Google sitemap.xml file. Because I have MSXML 4.0 installed, I finally decided to try validating my file as described in an older O'Reilly xml.com article, An Overview of MSXML 4.0 by Steven Livingstone, June 04, 2002

My sitemap file validated easily enough as far as being well-formed, but I also wanted to validate it against Google's schema file. After modifying the sample5.htm file to use my sitemap.xml file, IE gave this error

Error: file: ….. sitemap.xsd#/schema
[1]/element[position() = 6 and @name = 'priority']/simpleType
[1]/restriction
[1]It is an error for the value specified for minInclusive to be greater than the value specified for maxInclusive for the same datatype.

Checking Google's sitemap.xsd file shows this as the trouble area

<xsd:restriction base="xsd:decimal">
<xsd:minInclusive value="0.0"/>
<xsd:maxInclusive value="1.0"/>
</xsd:restriction>

So MSXML 4.0 considers the decimal 0.0 as being greater than the decimal 1.0 ???

I downloaded the schema file and changed the datatype to float, changed the script in the HTML file to use my modified local copy of the schema file and tried again. Success!

Of course a float is not a decimal, so this technique does introduce the possibilty of error, but I think it's better than not validating my sitemap file at all and hoping it's OK.

Technorati Tags: , ,