Buy me a Coffee
Web 2.0 Training
 
headermask image

Random Header :: Unpredictably Exciting

How to make a PHP 5 class work in PHP 4

Are you facing an error that says:

Parse error: parse error, expecting `T_OLD_FUNCTION’ or `T_FUNCTION’ or `T_VAR’ or `’}” in ….

Well chances are that you are trying to run a Class written for PHP5 in PHP 4. This is what you have to do in order to make a class written in PHP5 Class to work in PHP4 or for that matter in PHP 3.

  1. Remove all PUBLIC, PRIVATE and PROTECTED keywords.
  2. Prefix “var” keyword before each variable declared in the class.
  3. Rename the constructor of the class (of any) from __construct() to NameOfTheClass()
  4. Look for PHP 5 specific functions like simplexml_load_string() and replace/recode them with PHP4 equivalent code.

For Example:

In PHP 5

class  dummy() {

private $variable;

public function __constructor(){

//Contructor function....

}

public function getValue() {

..........

In PHP4

class  dummy() {

var $variable;

function dummy(){

//Contructor function....

}

function getValue() {

..........


If you liked my post, feel free to subscribe to my rss feeds

One Trackback

  1. By SourceForge.net: Aiuto UNITED STATES WordPress 2.2.1 on 29 December 2007 at 9:38 PM

    [...] della classe. Su questo blog c’è un riassunto delle compatibilità per le classi da PHP5 a PHP4: http://rochakchauhan.com/blog/2007/09/12/how-to-make-a-php-5-class-work-in-php-4/  Penso che il motivo sia [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*