Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP Version
#1
Bug 
Today I will talk a little about PHP, which version do you use?
______________________________________________
|PHP 5.2 | PHP 5.3 | PHP 5.4 | PHP 5.5 | PHP 5.6 | PHP 7.0|
PHP 5.4 was released after many months of development and testing. This article will give a brief description of the new features of version and talk about the criteria that you can follow to decide whether and when to upgrade to the new version.

PHP 5.4 features

PHP 5.4.0 was released earlier this month and is the result of many months of development.

Several features have been proposed for this release. Now you may be wondering what are the features that are really interesting. Let me talk more about some of them.

traits

PHP does not support multiple inheritance. This means that, unlike languages like C ++, you can not create a class inheriting the behavior of other multiple classes.

However, PHP has support to have classes with multiple interfaces since version 5. This is a straightforward approach inspired by the Java that avoids the problems of ambiguity in the implementation of multiple inheritance C ++.

The problem of using multiple inheritance or multiple interfaces is that creating bloated classes makes it easy to have inherited much more functions than they really need in practice.

Traits provide a simpler alternative. You can set a trait much the same way as defining a class or interface with any function you need. Then use them in a new class in which to have these functions.

Here is an example from RFC proposal of the original document:

PHP Code:
<? Php

 Trait ezcReflectionReturnInfo {
   getReturnType function () {/ * 1 * /}
   getReturnDescription function () {/ * 2 * /}
 }

 class ezcReflectionMethod extends ReflectionMethod {
   ezcReflectionReturnInfo use;
   / * ... * /
 }

 class ezcReflectionFunction extends ReflectionFunction {
   ezcReflectionReturnInfo use;
   / * ... * /
 }

?>
WebServer built

Although Apache will lose popularity in recent years for webservers more efficient in use in production environments, it is still very popular among PHP developers who use it to test their applications in their development environments.

However, Apache is still very heavy and complicated to set up, especially when you just want to set it to a simple development environment. So, PHP 5.4 introduces a webserver that is built into the PHP command line version.

This means that you only need to perform a simple PHP command and will have a webserver running ready for you to test your applications without relying on configuring Apache or any other external WebServer.

Another interesting aim of this embedded Webserver is that you can develop browser-based applications that run on the local machine and you only need the PHP installation base for this.

Here is an example as a command to run PHP to work as a WebServer.

Code:
$ Php -S localhost: 8000

Server is listening on localhost: 8000 ... Press CTRL-C to quit.
[Thu Mar 3 05:42:06 2011] :: 1: 56258: /
[Thu Mar 3 05:42:06 2011] :: 1: 56259: / = PHPE9568F34-A769-00AA02
[Thu Mar 3 05:42:06 2011] :: 1: 56260: / = PHPE9568F35-A769-00AA04
binary notation for integer values

When you need to use literal values in your PHP code, you can represent them in decimal hexadecimal or octal. Now, in PHP 5.4, you can also represent them in binary.

Octal, you need to prefix the value with a 0. For example, 010 is the number 8, not 10 as some may expect. In hexadecimal, you need to prefix the values with 0x - for example, 0x12 is the number 18 in binary, you must prefix the number with 0b - for example, 0b101 represents the number 5.

Short array Syntax

The popularity of the JSON become a common format for data exchange between the serialized code may be written in different languages.

A basic difference between JSON and the literal value format PHP is that arrays are represented by square brackets instead of building the usual array (). Some people have proposed to add support for a shorter syntax similar to JSON. The proposal was not approved by many of the PHP core developers, but many users voted for. Therefore, it is now possible to define an array like this:

PHP Code:
= [123];

= [ 'foo''orange''bar''apple''baz''lemon']; 
discontinued features

Some versions of PHP suspended old features. This is especially important versions like this. Generally, resources are suspended after being considered obsolete in previous versions.

In PHP 5.4, the magic quotes is a feature that has been suspended. It used to be activated if you have some options set in php.ini.

It was created to escape values for use in SQL queries automatically. The problem is that the use of this feature made PHP components from untrusted third parties, as it would need to check if the option was created to determine if they need to escape the values to use SQL queries.

Moreover, the correct literal value for escape depends on the database in which you are connecting. So it is more reliable to have the options disabled magic quotes and escape the values explicitly, possibly using the database-specific functions for this purpose, as 
PHP Code:
mysql_real_escape_string (). 

features left out

Many features have been proposed for PHP 5.4, but were not all made to this version, either because they were not approved by the core developers, or its proponents not developed enough to put them at launch. Here are some of the most important features that are not part of PHP 5.4.

caching extension APC

PHP compiles the code in Zend opcodes before running. This makes PHP run much faster than when it was an interpreted language before the days of PHP 4.

However, the opcode compilation process still consumes a significant amount of time, especially if your code uses a lot of external components scripts. This overload can be avoided if you use an extension cache. If you are using PHP busy WebServer, it is mandatory to use an extension opcode caching.

There are many extensions cache. Some are open source, others are commercial. APC is an open source cache extension developed by several core developers of PHP.

Despite the importance of using an extension opcode cache, PHP 5.4.0, APC is still not sent in the PHP distribution.

Initially, it was planned to do it in PHP 6, but the original plans for this major release were canceled. Then it was anticipated for PHP 5.4, but at least for PHP 5.4.0, it was alleged that the APC is not ready for that version.

This is not good news for PHP. Often, we see reference to PHP comparing it to other languages used on the Internet. Often, PHP installation used in the benchmarks is running without an opcode cache, while other languages use their own cache mechanisms.

It is an unfair comparison, but many people do not know these details, so they believe that PHP is much slower. PHP often seems to be missing because the reference values are not made with PHP running with an extension of cache.

annotations

Notes are a way to add metadata to your code. metadata information can be used by these tools, for example, to produce additional support code so you do not have to write this code manually. A common use is to generate a PHP code or SQL statements to map data between object classes and database tables.

There were several proposals to implement notes in PHP, very similar to the way they work in other languages, such as Java and C #. These proposals did not end up being accepted and fully implemented to be part of PHP 5.4.

Still, there are alternative approaches that consist of separate analisadoras annotation tools that extract metadata annotation PHP comments.

I use PHP 5.4?

Now you may be wondering if it is worth doing PHP 5.4. Here are some tips you may want to take into consideration. Some of the recommendations are so obvious, they might not really need to be given, but it will be done for you to make sure that this is just common sense.

It is a unanimous opinion never tamper with the team that is winning. If you looked at the features of PHP 5.4 and found something that might be interested in using, just do not worry about updating.

If you insist just because you want to be on top of the last wave, chances are that your PHP code can give problems due to changes of which you were not aware.

No, if you need extensions not supported

If you need some extensions that have not been built in PHP, such as an extension of cache, as mentioned above, chances are that these extensions may not yet be ready for this new version.

Thus, it is advisable not to update at least until they are updated to work with PHP 5.4, or may not update it until there is spare extensions for the same purposes.

Give it some time

I always say, new releases, new bugs. This means that it is virtually guaranteed that this new version will have bugs that can break your code.

Despite all the tests that PHP 5.4 has passed, there are always mistakes that will only be found after people begin to try it.

The most obvious bugs are fixed soon. So if you are really determined to update it in production, be wise and wait a while, maybe at least a month. This will give time for the core developers correct the most significant errors.

Try it on your development environment

Even if you do not update, nothing should stop you from using PHP 5.4 on your development environment. At worst, if it breaks your code, you can always downgrade without affecting the audience of your site, because only you or your team should use this development version.

Moreover, with the new version of the support to PHP 5.4 work as a WebServer, you do not need to uninstall an older version you are using. Just run it from the command line and see if everything works.

conclusions

It is always good for your community to see a new version of its product - in this case, PHP - be released because it shows good signs of vitality in the development of this language. If you will use the new version or not, there's another story.

In any case, congratulations to Stas Malishev, David Soria Parra (the release managers) and all other developers involved in the release of this version of PHP. Liking it or not, it is always a non-trivial task that requires a lot of power to put together a new version of such a popular language like PHP. Congratulations to everyone who gave their best to give life to PHP 5.4.

So what about you? Liked the features of version? Intends to use it? It has a different criterion for deciding than presented above? What other features not mentioned in this article you find relevant? Feel free to post a comment giving their views on the subject.
__                    
|_  _ |_  o  _ |      
|  (_||_) | (_)|__|_|><


If you enjoyed, please give me your like (:
Reply
#2
I'm actually using PHP 5 on my Web Server :B But i'm looking to upgrade it. Currently testing PHP 7 on localhost
Reply
#3
I'm using PHP Version 5.6, since version 7.0 has deprecated some methods that I use, and I still need to recode everything..
Reply
#4
I use PHP 5 and use PHP PDO prepared statements instead of the horrid "mysql_real_escape_string (). "
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)