Upgrading from Amfphp 1.9 to 2.x

We have tried to find a compromise between writing good, consistent code for v2, and supporting code that was written for prior versions.
To upgrade, put the new Amfphp on your server, and copy your services to the « Services » folder. V2’s service folder contains an example service, if you don’t need it just get rid of it.

What’s Changed

  • All folder names start with an Upper-case letter. For example, it’s « Services », not « services » now.
  • The old Flex based service browser is no longer available. There is however a html based service browser available at BackOffice/ServiceBrowser.php
  • no more ‘gateway.php’. It’s Amfphp/index.php, or simply Amfphp/ .
  •  By default, Amfphp will now check that the number of arguments you pass to a service method matches the number expected. See configuration.
  • you need to call session_start() before accessing session variables.
  • Somewhere buried in the v1.9 code is a change of the current folder to the Services folder. This has an impact for using relative paths from the service classes. If you use relative paths, in the Amfphp/index.php file you will a commented line:
    chdir(dirname(__FILE__) . "/Services");

    Uncomment this line if you have problems with relative paths. We do however encourage you to use absolute paths. These can be generated using dirname. See ClassLoader.php for an example.

Basic serialization works the same, however there are some changes regarding objects

    • Anonymous objects are now deserialized as objects, not arrays. So take for example in AS3 sending a simple object {userId:’user’, password:’test password’}. In older versions, to get the userId, you would use the following syntax: obj[‘userId’]. Now, this has changed to obj->userId.
    • Typed objects used to be necessarily linked to a real class that would typically be in the « services/vo » folder. There was all kinds of messy code to deal with this. Now things are much simpler. If Amfphp receives a typed object, it created an anonymous object where all the data is set, and the type is put in an additional reserved field: « _explicitType ». Furthermore, if you want to send back a typed object, all you have to do is set that same field on the object you return from your service and the client will receive a typed object. There is a plugin for using real classes contained in the old « services/vo » folder, AmfphpVoConverter, but you don’t need to use it anymore to be able to use typed objects.
    • returning resources is no longer supported. It was messy, and now DB abstraction layers do it way better. So no more « return mysql_query(‘SELECT * FROM BlaTable’) ». Rather Use a DB abstraction layer like PDO that will convert the resource to an array.
    • Support for object traits has been added. See ‘object traits’ in optimizing-amfphp. This demands a good grasp on most advanced amfphp subjects, but can save significant bandwidth in some cases.
    • Some of the more unusual types are now handled differently. See Amf Data Types for details.
    • There are no beforeFilter and afterFilter methods, rather there is a plugin system. For example authentication is handled by the Authentication plugin.



  1. hzor

    27 Juin 11

    « Anonymous objects are now deserialized as objects, not arrays. »

    Are there any way (config option) to keep this the old way?
    Other way we’ll have to rewrite a lot of php code to support this.

  2. ariels

    27 Juin 11

    sorry, unfortunately there is not.

  3. Delosgatos

    4 Août 11

    just use $input_array = (array)$input_object

Laissez un commentaire

News letter

Evénements Silex Labs sur Paris et sa région: Inscrivez vous à la Newsletter mensuelle

Silex Labs community Tweets

Facebook page