Wednesday, April 18, 2007

PHP: PHP 5 Deployment Error

I've written some code for PHP5, and deployed it to a production server and I saw an error that I'd never seen before.

PHP 5 Code:
<?php

class form
{
    public $name;
    public $fields;
}
?>


Error:
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in C:\x\y\page.php on line z


The problem is that PHP 4 has a different syntax for classes. The code above is PHP 5 valid, but not PHP 4. A valid version of its PHP 4 equivalent is this:

PHP 4 Code:
<?php

class form
{
    var $name;
    var $fields;
}
?>

No comments: