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 ...

Get Flash Remoting: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.