Notes on Java, Solaris, PHP, LDAP…

November 17, 2007

Migration PHP4 -> PHP5, PHP4 references and connection to MySQL

Filed under: Uncategorized — negev @ 9:23 pm
Tags: ,

18 June 07

Migration from PHP4 to PHP5
There is a PHP5 php.ini directive that puts PHP5 into PHP4
compatibility mode. In otherwords, your PHP4 scripts will for
sure [most likely] work. This directive is called: zend.ze1_compatibility_mode

If the compatibility mode doesn’t do it, try to reorganize code a little – e.g. constructors needing to be renamed…

Configuring PHP5 with Apache on SLES 10
– after installing Apache, PHP5, mod_php etc Apache
— make Apache start at boot time
— if need be, follow /usr/share/doc/packages/php5/README.SUSE

PHP5 and <? ?>

PHP5 has short_open_tag=off by default, which means that <? ?> and <?= ?> cannot be used. While <?php ?> can be used in place of the first tag, the next one must be replaced by <?php echo ?> which is makes code quite unreadable.

So how about having short_open_tag=on in php.ini?

PHP4 and references

We can use references for arguments and return them from the functions. There are at least a few tricky situations in PHP4 when references work weirdly or not at all:

  • returning/passing NULL by reference – it doesn’t make sense to do it, but if that happens then (my) PHP4 badly and quietly dies.

  • $myVariable =& $this→myField→itsFunction() generates a notice even when itsFunction() is defined to return by reference. Only $myVariable =& $this→myFunction() works.

  • references and global variables don’t really work together. Global variables are generally a bad idea, but sometimes we need them ($_REQUEST, $_SESSION). CakePHP session management doesn’t give access by references (and it it uses $_SESSION by default).

  • you need to keep track of your reference ‘links’ and when passing/retrieving data by reference you need to make sure that the functions don’t perform undesired/undocumented/unexpected side effects

  • if typing assignments by reference as =& then it’s easy to search/grep for them – in order to track any funny interaction

PHP mysql connection has its selected DB changed without any obvious reason
– PHP mysql_connect(..) by default reuses a connection if we pass same server, user & password several times.
– If we use those for several DBs then we want to pass an optional FALSE parameter to mysql_connect() to turn off this default behaviour. Or we can use same DB, or to have separate user for each DB.



  1. Good Information!!
    Moreover, in PHP 4, everything was public. In PHP 5, class designers can say what is externally visible (public) and what is visible only internally to the class (private) or to descendants of the class (protected).
    Another big addition were the keywords interface and abstract, which allow for contract programming

    Comment by Firos — February 8, 2008 @ 4:37 pm | Reply

  2. tIstF0 comment3 ,

    Comment by Ienczxxz — May 8, 2009 @ 8:56 am | Reply

  3. Is there any changes I need to do to a mysql scripts in php to convert them to php5?

    Comment by vaunce — June 24, 2009 @ 7:30 pm | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: