Tag Archive for '5.3'

Standard core PHP 5.3 extensions

When writing PHPT tests for PHP, it’s good practice to have a conditional --SKIPIF-- block to see if the test can be skipped when some extension you’re testing isn’t available. With the PHP_5_3 CVS branch (the one you should be testing against), some new extensions can’t be disabled, so the --SKIPIF-- block isn’t needed anymore. This applies to the following extensions: PCRE, Reflection and SPL.

In fact, the following extensions can’t be disabled so you can safely test against them without the --SKIPIF-- block:

  • date
  • ereg
  • pcre
  • Reflection
  • SPL
  • standard

For completeness, a short example for a Reflection test:

--TEST--
ReflectionClass::isAbstract() method
// THESE 2 LINES ARE NOT NEEDED --SKIPIF--
// REMOVE THEM! <?php extension_loaded('reflection') or die('skip'); ?>
--FILE--
<?php
 
abstract class TestAbstractClass {}
$abstractClass = new ReflectionClass('TestAbstractClass');
var_dump($abstractClass->isAbstract());
 
?>
--EXPECT--
bool(true)

__callStatic in PHP 5.3

This is cool (and a feature I’ve been missing in past projects): being able to implement a __call method for static class methods.
Like this:

1
2
3
4
5
6
7
class Foo
{
	public static function __callStatic($method, $args) {
		echo "Method $method has been called!" .PHP_EOL;
		echo "With following arguments: " .implode(", ", $args) .PHP_EOL;
	}
}

So you can call

Foo::anyMethod('with', 'any', 'arguments');

and have a working static class method.

In this case, the method outputs

Method anyMethod has been called!
With following arguments: with, any, arguments

This is already implemented in the PHP 5.3 and PHP 6 development versions.
For more information on what __call (and the future __callStatic) magic methods do, see php.net Method overloading