Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`new` and `use` keyword paths

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.

like image 719
John Papastergiou Avatar asked Aug 16 '11 20:08

John Papastergiou


2 Answers

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
like image 177
adlawson Avatar answered Nov 10 '22 17:11

adlawson


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.

like image 44
edorian Avatar answered Nov 10 '22 17:11

edorian