9.3 Datatype Conversions

The conversion of datatypes between PHP and ActionScript is straightforward, as shown in Table 9-1. These conversions work in both directions, from PHP to ActionScript and vice versa, with the exception of PHP arrays.

Table 9-1. PHP-to-ActionScript datatype conversion

PHP

Flash (ActionScript)

Null

Null

Integer

Integer

Double

Float

String

String

Array (normal)

Array

Array (associative)

Object

Object

Object

Resource[1]

Recordset

[1] The only supported databases are MySQL, ODBC, and PostgreSQL.

The conversion of PHP arrays to Flash ActionScript can be a bit confusing. In PHP, all arrays are associative arrays. Associative arrays can use any type of symbol, rather than just integers, for the index. This means that the following PHP code is perfectly legal:

$myList = new Array( );
$myList[0] = "apple";
$myList["foo"] = 12;

This fact means that, when coming from Flash, ActionScript objects of type Array and Object (a.k.a. structures) are converted to the PHP Array datatype. When converting an ActionScript Array to PHP, a PHP Array using entirely integer indexes is created.

The problem comes when translating PHP arrays to ActionScript. AMFPHP has to guess what is the best kind of ActionScript datatype to create from the PHP array. It does this by a simple process of elimination; if the PHP array contains any noninteger indexes, it is converted to the ActionScript Object datatype; otherwise, it is converted to the ActionScript Array datatype.

As of this writing, AMFPHP doesn't support the sending of PHP objects to Flash. Nor does it fully support the sending of objects created from custom ActionScript classes to PHP (they are seen as simple objects with no associated methods). The AMFPHP team is actively working on implementing these features, and they will probably be in place by the time you read this. Check the AMFPHP site for more information.



    Part III: Advanced Flash Remoting