Zend Weekly Summaries Issue #225

      Comments Off on Zend Weekly Summaries Issue #225

TLK: Internal pass-by-reference
BUG: segfault on passing arguments by reference
REQ: C++ library wrapper
TLK: class_exists() and realpath()
TLK: Before March 1st…
NEW: Custom object serializing infrastructure
TLK: PDO questions
TLK: 5.0.4 RC1 delay
TLK: Approved bison versions
CVS: Win32 backtraces made possible
PAT: Poor Fred

TLK: Internal pass-by-reference

Extension author Chris Cranford got off to a false start when he asked how to
pick up key/value pairs by iterating over an array. The only response was given in PHP.

Evidently a hardy chap, Chris persevered with a carefully worded question about
passing variables to an internal function by reference without enabling the
deprecated allow_call_time_pass_reference switch in php.ini.
Marcus Börger responded this time, pointing Chris to ZEND_ARG_INFO and
the macros available in zend_api.h. Brad House followed up with an example of
those macros in use in ext/mcve‘s

Chris wondered where second_arg_force_ref() was defined – it was
giving him compiler issues. Was there an example he could use?

Brad explained that it was only defined in zend_modules.h in PHP 5; in PHP
4 you’d need to manually define it:

static unsigned char second_arg_force_ref[] =

He added, ‘As far as usage, you pretty much define it as by reference, and
just set the variable as you’d like, just make sure you dereference it (e.g. use
*arg2 not arg2 or whatnot after getting the reference using

Short version: Hard-to-find advice for extension writers.

BUG: segfault on passing arguments by reference

Martin Sarsale wrote in to say that his large project was doing some very strange
things following an upgrade to PHP 4.3.10. He was seeing a lot of segmentation
faults. He’d installed php-mmturck, and provided a choice moment from his Apache
error log:

Line 58 contained:


Derick Rethans had noticed the same thing, and was still trying to figure out
where it happens, but felt that ‘it has most likely to do with
returning-by-reference in the wrong places
‘. He noted that it was difficult to
reproduce the problem.

Michael Walter had also experienced this problem, this time in a medium-sized
code base. He reported seeing a crash even with ‘correct’ code such as:

() {


Todd Ruth, who had previously reported this
, said that he’d ended up by hacking a p*rl script[sic] to find
attempts to use non-referencable things as references‘ in his company’s code
base, and would like to see a better tool for doing this. He’d found that:

() {

function h(&$x) {
= 5;

could cause PHP to crash – but only if the code base was large enough.

Martin reported that, having tested several PHP 4 versions, PHP 4.3.5 was the
last to give him no problems. He’d downgraded as a consequence, and was now living
with the problem of applying security patches intended for later versions of

Short version: Mystery bug in PHP 4.3.6 and up affecting large code bases.

REQ: C++ library wrapper

New extension writer Arjun Jain wrote asking whether there were any options other
than ext_skel and PECL_Gen for spawning a PHP extension. The API he was working with
was written in C++ and continually being updated. He had hoped to find a way to load
those libraries and simply expose the interface in PHP, rather like the ImageMagick
library, given that maintenance was likely to be a problem. Was this possible?

Fellow extension newbie Tim Van Wassenhove pointed Arjun to a tutorial on Jay
Smith’s site,
[dead link], saying he might find it useful. He probably did – it’s an excellent resource.

Editor’s note: Jay has been contacted with an offer of hosting. Watch this space…

Short version: Check that link :-)

TLK: class_exists() and realpath()

Stephan Schmidt of PEAR reported ‘strange behaviour’ on the part of
class_exists() in PHP 5, saying that the __autoload()
function wasn’t responding as it should. Marcus pointed out that the second
parameter in class_exists() should be set to ‘true‘, to
force __autoload(); ‘“RTFM” or is it undocumented?
Oooops….‘ wrote Stephan.

Undeterred, he wrote again a few hours later to say that realpath()
reported the path to the document root when called from the constructor, but the
path to the PHP installation when called from the destructor. Johannes Schlüter
pointed out that this was by design, and should also happen on Linux where mod_php
was used.

Daniel Convissor reported that he was seeing different realpath()
behaviour in this respect depending on whether he used Win 2K (document root) or Win
XP (PHP installation) when running PHP as CGI.

Short version: The last of these probably isn’t by

TLK: Before March 1st…

Adding to last week’s PHP 5.1 TODO list, Lukas Smith highlighted the need for the
installer in PEAR 1.4 that Greg Beaver had been working on. ‘Getting this in…
will improve the life for pecl considerably
!’ As with PDO, testers were needed
for this.

Greg added that he planned to release PEAR 1.4.0a1 during the coming week, and
expected the first beta version to be ready in time for PHP 5.1 beta 2. Should he
stay with PEAR 1.3.5 for PHP 5.1 stable, or try to get PEAR 1.4.0 stable into PHP
5.1 stable? When should we expect to see 5.1 stable’s release?

Derrell Lipman asked that the embedded sqlite be upgraded to 2.8.16, citing a
database corruption issue when using VACUUM in the current version.
Nuno Lopes noted that the same applied to the version of SQLite 3 used in

Wez Furlong replied that both SQLite updates were already on his TODO.

Short version: PEAR install testers required.

NEW: Custom object serializing infrastructure

Stanislav Malychev wrote a long letter to the internals list explaining his Zend
Engine changes to allow custom object serialization/unserialization inside the
existing mechanism. His letter is reprinted here in full:

Short version: Wow.

TLK: PDO questions

Ard Biesheuvel popped his head up from beavering away at PDO_FIREBIRD to ask a
couple of PDO-related questions:

Alan Knowles remarked that it was currently almost possible to bypass
PDO’s PHP API and talk directly to the drivers via PDO, and that this was greatly
aided by the fact that the back ends were designed not to return zvals
in most instances (meta being the notable exception).

Wez explained that ‘PDO doesn’t believe in doubles‘ due to the lack of
precision inherent in float conversion. The idea of stmt_get_col() was
to return the native C type and leave it to PDO to manage zval creation
as appropriate, thereby simplifying the common cases in database driver

Short version: It was thought about.

TLK: 5.0.4 RC1 delay

In response to a query from PHP user Adam Golebiowski, Andi explained that there
were still issues outstanding that were holding up the 5.0.4 release candidate.
However, he still expected to see it happen within the next week.

Short version: Same old, same old.

TLK: Approved bison versions

Sebastian Bergmann, responding to Jani Taskinen’s assertion that PHP would only
build alongside bison 1.28, 1.35, 1.75 or 1.875, reported that bison 2.0 also worked
seamlessly for him.

Jani felt that it was far too early to add such a recent bison release to the
‘approved’ list.

Short version: Jani has a strangely cautious moment.

CVS: Win32 backtraces made possible

The more interesting CVS commits this week include:

  • Ilia Alshanetsky’s scandir() performance improvement
  • Marcus’ enforcement of dtor() calls as default behaviour (fixing
    several __destruct() bugs)
  • Jani’s cleanup of the build system, including implementation of Zend-specific
    autoconf functions
  • Stas’ custom object serializer infrastructure as detailed above
  • Edin Kadribasic’s --enable-debug-pack configure option for the
    Windows build

The new configure option creates a zip file containing *.pdb debug
symbol files, enabling Windows users to use the free debugging tools available at
http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx to
generate a backtrace, at least on MSVC 6.0 (untested elsewhere). Edin added a note
that the CFLAGS used are described in http://support.microsoft.com/default.aspx?scid=kb;en-us;291585.

Edin also made changes allowing arbitrary files to be added to the distribution
build with ADD_DIST_FILE(filename), which should make his own life
easier if nobody else’s.

Short version: Heroes of the week: Edin and Stas.

PAT: Poor Fred

Frédéric LeCointre, having rewritten php_check_syntax_string() about
eight times, asked whether the function could be added now, alongside a note that it
had the same limitations as php_check_syntax().

Peter Brodersen wrote chasing up a security issue he’d reported on the internals
list earlier. This being entirely the wrong place for security discussions, nobody
replied. There is an email-only list, security@php.net – non-public, for obvious

Kamesh Jayachandran, working on the NetWare port of PHP, reported errors when
testing during cross compilation of his binaries under Linux. He provided a patch,
which Jani subsequently committed ‘without the echo though as that is
‘. Kamesh pointed out that the patch no longer worked, and provided a
new one. Jani also made a few small changes here, but without any problems this
time. He also reviewed and committed later build patches for Kamesh, allowing
win32/sendmail.c to be compiled and pthread support to be enabled for

Antony Dovgal supplied a patch for the Zend Engine part of the Reflection API,
fixing bug #32076. Derick
subsequently reviewed and applied it.

Moriyoshi Koizumi included one of Joe Orton’s fixes alongside a bunch of changes
synchronizing ext/mbstring with the latest libmbfl checkouts, and Andi
committed another from Joe adding a missing include file to the Zend Engine build.
Meanwhile, Joe and Rob Richards were working together throughout the week to refine
Joe’s patch avoiding encoding auto-detection in earlier versions of libxml 2.

Antony Dovgal committed a bug fix from another Stanislav (not the Stas)
allowing ext/oci8 to be built as a shared module. He also reviewed and turned
down a Zend Engine patch from Val Khokhlov after the latter complained that
zend_vm_set_opcode_handler(zend_op* op) should be exported, explaining
the VM generating mechanism to Val in a single sentence.

Short version: php_check_syntax_string() got ignored because your URL doesn’t work, Fred.