subscribe

SabreAMF 0.6 -> upgrade recommended

Edwin Koster found a pretty big bug in AMF3 deserializing, which was actually also identified by Patrick Mineault right before my vacation.. Thanks for those bug reports!

That one’s fixed now.. It was related to AMF3 object deserialization. For the people using SabreAMF for their flex projects: Upgrading is highly recommended!

IExternalized and ArrayCollection

Additionally, I added IExternalized-object support. What most likely the biggest change is for people, is that the ArrayCollection object now arrives differently. Before it would have been an anonymous object with the source property containing the data, now there’s an actualy php equivalent for the ArrayCollection object, namely SabreAMF_ArrayCollection.

If you want to see how it works, I’d recommend simply checking out the source.

For people who don’t know PHP5’s SPL objects too well, the ArrayCollection implements IteratorAggregate, Countable and ArrayAccess.. in practice this means you can do most general Array operations on this object..

<?php

$data = array();
$data[] = array('property1'=>'yo','property2'=>'test2');
$data[] = array('property1'=>'foo','property2'=>'bar');

$arrayCollection = new SabreAMF_ArrayCollection($data);

foreach($arrayCollection as $row) {

   // So yea, you can just loop through it like a normal array (done through IteratorAggregate)

}

// Or get values straight from a certain row (done through ArrayAccess)
echo($arrayCollection[0]['property1']);

// Or get the total number of rows (done through countable)

echo(count($arrayCollection));

// In the case you need a normal array, based on the ArrayAccess class

$normalArray = iterator_to_array($arrayCollection);

?>

If you want to check out how to create your own externalized objects.. (remember this always has to go paired; create one in flex, and create one in php), base your class on the SabreAMF_Externalized interface.

Also, be sure to let me know if there are any other well known flex classes that could really use SabreAMF equivalents..

The only other change is, that if exceptions don’t provide a value for the ‘code’ property, the classname is passed by default.

Upgrade/Download

As usual you can upgrade using:

pear upgrade http://www.rooftopsolutions.nl/code/SabreAMF/downloads/SabreAMF-latest.tgz

Or do a fresh install with:

pear install http://www.rooftopsolutions.nl/code/SabreAMF/downloads/SabreAMF-latest.tgz

Mailing list

I’d also like to point out that there’s a mailing list do drop your questions.. The response might be quicker than the comment box..

Subscribe at osflash.

Web mentions

Comments

  • Tom

    Thanks for the update!
  • Tom

    Sorry for the double comment... I noticed something with this release that may or may not be problematic depending on your stance on backwards-compatibility. The type hinting (array type hinting in particular) and use of the Countable interface in SabreAMF_ArrayCollection breaks in versions of PHP less than 5.1.

    Also, many of the SabreAMF files don't use relative class inclusions which they probably should.
  • Evert

    Evert

    Hi Tom,

    The array type hinting was an easy fix, I actually removed this now on SVN.. so this will be out with 0.7 (which is going to happen fairly soon..)

    My general stance of backwards compatibility is.. I always go for the latest version, unless its an easy fix.. I believe we should be using the power we've been given ;)

    As for the relative class inclusions.. this is general practice for most framework-type code.. (PEAR/Zend Framework and many others)

    First, you normally shouldn't have to worry if you install it using pear.. if you manually install it and the source is not right in your webroot (this is actually what I do.. I embed it in a lib/ directory) You can use the following line to make things relative again:

    ini_set('include_path',ini_get('include_path') . PATH_SEPERATOR . dirname(__FILE__) . '/lib);
  • Evert

    Evert

    Last line should say:

    ini_set('include_path',ini_get('include_path') . PATH_SEPERATOR . dirname(__FILE__) . '/lib');
  • Tom

    Hi,

    I am a programmer too and always try to use the power we've been given, like you said. ;) However, many shared hosting environments haven't updated to PHP 5.1+ yet. I'm just thinking about making this easier for wide-spread use.

    Whenever I code any sort of PHP app I tend to use relative class inclusions but I guess that's just me, hehe. You are right that it is general practise not to do this.

    You may also want to switch UnderflowException used in InputStream.php with an ordinary Exception since RuntimeException and its subclasses weren't implemented until PHP5.1 either.

    I'm anticipating the 0.7 release and I'll let ya know if I see any more easy fixes.
  • Evert

    Evert

    I changed UnderFlowException into a normal exception as well.. Good catch..

    Don't forget that you can always make use of the SVN version, as this is 99% of the time in a stable state (and you'll get updates a lot quicker..)
  • Develar

    Develar

    Why SabreAMF_AMF3_ErrorMessage not provide "error line"?

    I think, you should work on last version PHP. We are programmers, but not coders.
  • Evert

    Evert

    Hi Develar,

    I intended to write a 'debug mode' of some sort.. When its switched on you'll see the error line and file, when its off you don't (handy for security reasons)..

    But yea, its a TODO.. thanks for the heads-up. I don't totally get what you mean with your second comment.. I consider coder and programmer the same thing and I always make sure everything works with the latest PHP version ( I actually always run the latest version, except when its a .0)