Tag Archive for 'extensions'

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:

ReflectionClass::isAbstract() method
// REMOVE THEM! <?php extension_loaded('reflection') or die('skip'); ?>
abstract class TestAbstractClass {}
$abstractClass = new ReflectionClass('TestAbstractClass');

Configuring PHP: --with-extension or --enable-extension?

This is a small thing that got me wondering in the past but it wasn’t until recently, when I started picking up developing PHP extensions, that I wanted to know: when does one use --with-extension and when does one use --enable-extension? The answer is easy but you just have to remember ;-)

--with-extension is used if you want to refer to an external directory or libraries, for example --with-mysql[=DIR]. The extension can’t be built without external mysql headers, thus the –with switch.

--enable-extension is used if you just need to tell PHP to enable the extension in question, for example --enable-mbstring. Mbstring support is built in with PHP, you just tell it to enable it.

You should know that, if you are building your own extension, you should only pick and use the one that is most appropriate for your extension, but never both.