Monday, August 21, 2006

__get() and array rumors

There've been lots of rumors about overloaded array properties lately.


The following code



<?php
class funky {
private
$p = array();
function
__get($p) {
return
$this->p;
}
}
$o = new funky;
$o->prop["key"] = 1;
?>


will yield:


Notice: Indirect modification of overloaded property funky::$p has no effect

As arrays are the only complex types that are passed by value (resources don't really count here) the solution to described problem is simple: use an object; either an instance of stdClass or ArrayObject will do well, depending if you want to use array index notation.


So the folloiwng code will work as expected, because the ArrayObject instance will pe passed by handle:



<?php
class smarty {
private
$p;
function
__construct() {
$this->p = new ArrayObject;
}
function
__get($p) {
return
$this->p;
}
}
$o = new smarty;
$o->prop["key"] = 1;
?>

I guess most of you already knew, but anyway... ;)

Friday, August 18, 2006

Round up

It's been a long time since I wrote something here, mostly because I got distracted by some real private life recently ;) and due to paid work of course. Therefore I thought I'd round up what has happened behind the scenes in my PHP world.


PHP-6
I rewrote the output control layer for PHP-6 some months ago and I'm about to upgrade ext/zlib to see how it really works out.


PHP-5.2
I didn't contribute that much to this upcoming release. Two things I'd like to mention are a fix for the Apache2 SAPI where each header("Content-Type: aaa/bbb") caused Apache to add output filters for the type to the outgoing filter chain and the addition of the error_get_last() function, which is a convenient accessor to the last occured error without fiddling around with INI(track_errors) and $php_errormsg.


pecl/http
There's official documentation now available online in the PHP manual, yay! :) It's not fully fleshed out, but gives some feeling about the provided functionality and hints on how to use this module.


php|a published an article by me about pecl/http in their Augusts issue!


There have also been three releases since 1.0, the most recent one (1.2) today. See the changes since then outlined below.


Improvements/Additions



  • Improved response performance (HttpResponse, http_send API)

  • Added http_build_cookie() function

  • Added HttpQueryString::mod(array $params) method

  • Added ArrayAccess to interfaces implemented by HttpQueryString

  • Added HttpMessage::getHeader(string $name) method


Bug Fixes



  • Fixed http_parse_cookie() allowed_extras and flags parameters

  • Fixed configuration with shared dependencies

  • Fixed endless loop in http_build_url("..")

  • Fixed HttpResponse::capture() failure if buffered output exceeds 40k

  • Fixed HttpQueryString failures with objects as params

  • Fixed memory leaks with overloaded classes extending HTTP classes

  • Fixed build with gcc-2.95 (Thanks to Alexander Zhuravlev)

  • Fixed memory leak in inflate code (Thanks to Thomas Landro Johnsen)