tongro
tongro

Reputation: 11

How to make PHP5 emulate older version?

I'm writing a web app on my system using PHP5, but the app needs to be compatible with PHP4. Is there any way to emulate PHP4, or at least issue warnings?

Thanks.

Upvotes: 1

Views: 996

Answers (3)

hashchange
hashchange

Reputation: 7225

There is no way to emulate PHP4 that I'm aware of. You need to run your code in a real PHP4 environment. Here's what I'd suggest:

  • Grab an old distro which includes a PHP4 package. Apparently, Ubuntu Dapper (6.06) does.
  • Install it into a VM (VirtualBox or VMWare) on your box.
  • Create a shared directory for the VM which points to your app dir on the real box.
  • Inside your VM, create a symlink from the webroot to the mount point of the shared directory.

Once that is done, you can more or less forget about the VM. All you need to do is keep it running. Change your code in your app dir as before. You can run it from your browser with the IP of the virtual machine.

(Perhaps you could even install an old version of XDebug in the VM and do proper remote debugging from within your IDE. But I don't know if XDebug is compatible with PHP4 at all.)

Upvotes: 1

Jon
Jon

Reputation: 437366

No, there isn't. You will have to install PHP 4 on the machine to provide the runtime environment. Or, even better, convince the client that PHP 4 in 2012 is... outdated.

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324630

As a general rule, if you avoid functions and arguments that were added in PHP5 (as shown in the documentation for each function), then it should work just fine with PHP4. PHP is good at backwards-compatibility like that.

Upvotes: 1

Related Questions