Extreme newbie to php looking for insight...

I apologize in advance for being so completely new to php and my naivety.

I have been forced into learning php due to “zero” support from the developers of my web sites software script. Regretfully this is now an extreme crash course that I am trying to field, and I am aware I will never be able to tackle my current project within the time frame I truly need… But you have to start some where!

So here’s my ordeal. My current host, like most others, is dropping support for 5.2 and 5.3 versions of php… in my case it is my software script written in php 5.2 that will not long be functional. As such, I have jumped in with no water wings to find as much information as I can find on how to upgrade my current script to 5.6. I have to admit it is quite overwhelming when you have never really looked at php before.

I spoke to my web hosts development team twice so far trying to get information on what I need to do and I am a little confused from their two different answers. I have been told by the first person that in order to migrate or upgrade my script to 5.6 I would need to first update it to 5.3, then 5.4 and so on until I am compliant to 5.6. The second person I spoke to stated I could just redo the script to go from 5.2 straight to 5.6. So I am a little confused on what will need to be done… the first seems most likely when I consider each version has changes respectively that would need to be taken into account when modifying the script.

To my understanding, from my internet reading, the differences between current and legacy versions of php are generally update changes of structural code. In some cases previous command no longer supported and newer commands developed for better performance and security. Please correct me if I am way off base here… I can’t learn without getting some insight.

Is there a debugger or software that can run a legacy php script and compare the 5.2 functions against 5.6 php library to help me find out what needs to be change and where?

My site script is very large and this will take me forever at my current rate, and to be honest I don’t think it is financially worth hiring an outside source to update the script for me, so I’m trying to use it to learn and in the end make it 5.6 compliant so it can be used again.

Any insight into this cluster would be greatly helpful.

Again… my apologies for such a newbie question.

73s

The latter person could be more correct, but it depends. Is the site built in a framework/ CMS or is it custom code? If memory serves, there were not drastic changes in those versions, my company still uses 5.4 for a very secure system. I would advise you to pull a copy of you site down to your local machine, install something like XAMPP on your computer with the proper version (5.6) and see what happens.

The other option, is to find a company that still offers the legacy version you are running. Believe it or not, it isn’t that difficult, I still know of [large] web hosting companies that allow PHP 4 due to strong legacy requirements.

I have been checking into servers and so far all the host have informed me that they are dropping php 5.2 and 5.3. I have checked with a few other major hosting servers out there and have been told the same thing. Most are dropping 5.2 starting next month, and then 5.3 by 2016. So of the servers I spoke to have both 5.2 and 5.3 being dropped next month! The bigger hosting servers own so many smaller hosting servers that even when someone thinks they are dealing with a smaller entity they are actually with one of the big companies and they all get changed! So my situation demands that I find a way to check my script against current standards and find out what needs to be modified to keep it compliant and up to date… preferably 5.6.

As for whether it is done in framework/CMS? I truly do not know… nor am I aware how to determine this. This is whole php jump is all new to me and I am trying to gain as much information and knowledge as I can manage so I can start the journey into modifying my script so it can be used again.

I have been reading up on php code sniffer in hopes that will shed some light on my scripts 5.6 incompatibility. Again… my background is not remotely close to this type of thing.
If I can find a way to run my script and be told what is not compatible with 5.6, that is a start… then I can keep moving forward to find the needed changes as I go.

I have installed wamp on my machine today as a tool as well.

I understand the fact that some functions in 5.2 are no longer supported and no longer exist in 5.6. In each new version of php from 5.3, 5.4, 5.5 and 5.6… each having changes to the previous structure of the codes language and functions. I have to find a clear list of changes made to between versions. If I can see what was replaced and no longer used from one to the other I can perhaps start making the needed changes in my current script, and hopefully I can manage to get it to run again.

Getting information has been a chore for the most part.

I’m guessing you want this “just working” - getting this script up to date would require a rewrite as PHP has changed a lot the last 6 years.

I think I’d just fire up a dev environment with the PHP version I wanted, turn on all error reporting and start removing errors.

Here is the list though

Backward Incompatible Changes

[ul][li]The newer internal parameter parsing API has been applied across all the extensions bundled with PHP 5.3.x. This parameter parsing API causes functions to return NULL when passed incompatible parameters. There are some exceptions to this rule, such as the get_class() function, which will continue to return FALSE on error.[/li]
[li]clearstatcache() no longer clears the realpath cache by default.[/li]
[li]realpath() is now fully platform-independent. Consequence of this is that invalid relative paths such as FILE . “/…/x” do not work anymore.[/li]
[li]The call_user_func() family of functions now propagate $this even if the callee is a parent class.[/li]
[li]The array functions natsort(), natcasesort(), usort(), uasort(), uksort(), array_flip(), and array_unique() no longer accept objects passed as arguments. To apply these functions to an object, cast the object to an array first.[/li]
[li]The behaviour of functions with by-reference parameters called by value has changed. Where previously the function would accept the by-value argument, a fatal error is now emitted. Any previous code passing constants or literals to functions expecting references, will need altering to assign the value to a variable before calling the function.[/li]
[li]The new mysqlnd library necessitates the use of MySQL 4.1’s newer 41-byte password format. Continued use of the old 16-byte passwords will cause mysql_connect() and similar functions to emit the error, “mysqlnd cannot connect to MySQL 4.1+ using old authentication.”[/li]
[li]The new mysqlnd library does not read mysql configuration files (my.cnf/my.ini), as the older libmysqlclient library does. If your code relies on settings in the configuration file, you can load it explicitly with the mysqli_options() function. Note that this means the PDO specific constants PDO::MYSQL_ATTR_READ_DEFAULT_FILE and PDO::MYSQL_ATTR_READ_DEFAULT_GROUP are not defined if MySQL support in PDO is compiled with mysqlnd.[/li]
[li]The trailing / has been removed from the SplFileInfo class and other related directory classes.[/li]
[li]The __toString() magic method can no longer accept arguments.[/li]
[li]The magic methods __get(), __set(), __isset(), __unset(), and __call() must always be public and can no longer be static. Method signatures are now enforced.[/li]
[li]The __call() magic method is now invoked on access to private and protected methods.[/li]
[li]func_get_arg(), func_get_args() and func_num_args() can no longer be called from the outermost scope of a file that has been included by calling include or require from within a function in the calling file.[/li]
[li]An emulation layer for the MHASH extension to wrap around the Hash extension have been added. However not all the algorithms are covered, notable the s2k hashing algorithm. This means that s2k hashing is no longer available as of PHP 5.3.0.[/li]
[li]Safe mode is no longer supported. Any applications that rely on safe mode may need adjustment, in terms of security.[/li]
[li]Magic quotes has been removed. Applications relying on this feature may need to be updated, to avoid security issues. get_magic_quotes_gpc() and get_magic_quotes_runtime() now always return FALSE. set_magic_quotes_runtime() raises an E_CORE_ERROR level error on trying to enable Magic quotes.[/li]
[li]The register_globals and register_long_arrays php.ini directives have been removed.
mbstring.script_encoding directives have been removed. Use zend.script_encoding instead.[/li]
[li]Call-time pass by reference has been removed.
The break and continue statements no longer accept variable arguments (e.g., break 1 + foo() * $bar;). Static arguments still work, such as break 2;. As a side effect of this change break 0; and continue 0; are no longer allowed.[/li]
[li]In the date and time extension, the timezone can no longer be set using the TZ environment variable. Instead you have to specify a timezone using the date.timezone php.ini option or date_default_timezone_set() function. PHP will no longer attempt to guess the timezone, and will instead fall back to “UTC” and issue a E_WARNING.[/li]
[li]Non-numeric string offsets - e.g. $a[‘foo’] where $a is a string - now return false on isset() and true on empty(), and produce a E_WARNING if you try to use them. Offsets of types double, bool and null produce a E_NOTICE. Numeric strings (e.g. $a[‘2’]) still work as before. Note that offsets like ‘12.3’ and ‘5 foobar’ are considered non-numeric and produce a E_WARNING, but are converted to 12 and 5 respectively, for backward compatibility reasons. Note: Following code returns different result. $str=‘abc’;var_dump(isset($str[‘x’])); // false for PHP 5.4 or later, but true for 5.3 or less[/li]
[li]Converting an array to a string will now generate an E_NOTICE level error, but the result of the cast will still be the string “Array”.[/li]
[li]Turning NULL, FALSE, or an empty string into an object by adding a property will now emit an E_WARNING level error, instead of E_STRICT.[/li]
[li]Parameter names that shadow super globals now cause a fatal error. This prohibits code like function foo($_GET, $_POST) {}.[/li]
[li]The Salsa10 and Salsa20 hash algorithms have been removed.[/li]
[li]array_combine() now returns array() instead of FALSE when two empty arrays are provided as parameters.[/li]
[li]If you use htmlentities() with asian character sets, it works like htmlspecialchars() - this has always been the case in previous versions of PHP, but now an E_STRICT level error is emitted.[/li]
[li]The third parameter of ob_start() has changed from boolean erase to integer flags. Note that code that explicitly set erase to FALSE will no longer behave as expected in PHP 5.4: please follow this example to write code that is compatible with PHP 5.3 and 5.4.[/li]
[li]Support for Windows XP and 2003 has been dropped. Windows builds of PHP now require Windows Vista or newer.[/li]
[li]All case insensitive matching for function, class and constant names is now performed in a locale independent manner according to ASCII rules.[/li]
[li]Changes were made to pack() and unpack() to make them more compatible with Perl:[/li]
[li]Prior to PHP 5.5, cases existed where the self, parent, and static keywords were treated in a case sensitive fashion. These have now been resolved, and these keywords are always handled case insensitively[/li]
[li]The GUIDs that previously resulted in PHP outputting various logos have been removed. This includes the removal of the functions to return those GUIDs.[/li]
[li]Extension authors should note that the zend_execute() function can no longer be overridden, and that numerous changes have been made to the execute_data struct and related function and method handling opcodes.[/li]
[li]Array keys won’t be overwritten when defining an array as a property of a class via an array literal[/li]
[li]json_decode() now rejects non-lowercase variants of the JSON literals true, false and null at all times, as per the JSON specification, and sets json_last_error() accordingly.[/li]
[li]All encrypted client streams now enable peer verification by default. By default, this will use OpenSSL’s default CA bundle to verify the peer certificate. In most cases, no changes will need to be made to communicate with servers with valid SSL certificates, as distributors generally configure OpenSSL to use known good CA bundles.[/li]
[li]GMP resources are now objects. The functional API implemented in the GMP extension has not changed, and code should run unmodified unless it checks explicitly for a resource using is_resource() or similar.[/li]
[li]mcrypt_encrypt(), mcrypt_decrypt(), mcrypt_cbc(), mcrypt_cfb(), mcrypt_ecb(), mcrypt_generic() and mcrypt_ofb() will no longer accept keys or IVs with incorrect sizes, and block cipher modes that require IVs will now fail if an IV isn’t provided.[/li]
[li]Uploads using the @file syntax now require CURLOPT_SAFE_UPLOAD to be set to FALSE. CURLFile should be used instead.[/li][/ul]

[hr]

Please also note that in PHP 5.5 the mysql_* library was (finally) deprecated - meaning it will no longer work if you upgrade to PHP 7 (which in fact is just around the corner). This means you have to rewrite all your queries, preferably updating them to todays standards using placeholders instead of inserting data directly. So “SELECT * FROM USER WHERE ID = lots_of_escape_functions($id)” turns into “SELECT * FROM USER WHERE ID = ?”

http://php.net/manual/en/migration53.php
http://php.net/manual/en/migration54.php
http://php.net/manual/en/migration55.php
http://php.net/manual/en/migration56.php

I greatly appreciate the information. I don’t know if this revision is worth myself getting into or not. It does seem like a lot of work to go through. It might be time to just change the site completely to a different theme and template using an opensource code.

But I will pay with my script and see what I can manage… who knows, while I learn some php I might have some success, and be able to use it again.

:slight_smile:

73s

Sponsor our Newsletter | Privacy Policy | Terms of Service