8

Im on a host company that uses php 5.2 , some of the libraries i use are written in 5.3 and there are certain incompatibilities between the code.

First of all what is the alternative to :

use \folder1\folder2\class_file;

Secondly what is the alternative to :

$sample = new \folder1\folder2\class_file($arg1, arg2);

Thanks in advance.

Sunny Patel
  • 7,830
  • 2
  • 31
  • 46
John Papastergiou
  • 999
  • 2
  • 14
  • 29
  • "new \folder1\folder2\class_file($arg1, arg2);" is the alternative to "use \folder1\folder2\class_file;", hence avoiding the use of "use". – Ajay Singh Jul 15 '18 at 05:35

2 Answers2

14

Namespaces are not backward compatible with PHP < 5.3

You're going to have to:

  • remove all cases of namespace and use statements
  • rename your classes from class_file to folder1_folder2_class_file (or similar)
  • use $sample = new folder1_folder2_class_file($arg1, $arg2); to create an instance
adlawson
  • 6,303
  • 1
  • 35
  • 46
7

I'd say it depends on the amount of PHP 5.3 code and if your project is worth more than 5 Bucks per month to you.

My main suggestion is: Change your hosting provider.

If they don't offer PHP 5.3, a PHP Version released at the 30th of June 2009 (thats two years!) you are better of just not wasting your time trying to get your project to run there.

5.3 is mature enough to be used in production and 5.2 has reached the end of its life cycle( end of support for php 5.2 branch ).

Just don't waste your time creating an 'old' application because of some hosting company.

edorian
  • 38,542
  • 15
  • 125
  • 143