Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ PHP 5.3 New Features Detail     - Bash variable expansion modifier (Programming)

- Use dump restore mode fast backup and recovery system FreeBSD (Linux)

- Lucene Getting Started Tutorial (Server)

- A deep understanding of Java enum (Programming)

- Python MySQL database connection (Database)

- How to create an alternative Android / iOS connected wireless hotspot AP in Ubuntu 15.04 (Linux)

- Teach you how to synchronize Microsoft OneDrive in Linux (Linux)

- Virtualization and IT cooperation (Linux)

- Selection sort, insertion sort, and Shell sort (Programming)

- CentOS 6 kernel upgrade to Kernel 3.x (Linux)

- Source Analysis: Java object memory allocation (Programming)

- Hadoop2.4.0 Eclipse plug-in making (Server)

- RHEL6.4 one key installation Redmine (Linux)

- Oracle study notes view (Database)

- JQuery implements the same content merge cells (Programming)

- RedHat Linux 6.4 install Oracle 10g error (Database)

- RedHat 6 xrdp use remote login interface (Linux)

- Log4j configuration file Explanation (Linux)

- Use libpq under Ubuntu 14.04 (Linux)

- Python Dir find a folder several files (Programming)

 
         
  PHP 5.3 New Features Detail
     
  Add Date : 2018-11-21      
         
         
         
  1 PHP 5.3 new features

1.1 supports namespace (Namespace)

There is no doubt that the namespace is PHP5.3 brought about the most important new features.

In PHP5.3, only the need to specify a different namespace, the namespace separator is a backslash \.

//select.php
    namespace Zend \ Db \ Table;
    class Select {

    }
?>

Even though the presence of a class named Select other namespace in the call will not conflict. Readability of the code has also increased.
Call the method:

//call.php
    // Namespace Zend \ Db;
    include ( 'select.php');
    $ S = new Zend \ Db \ Table \ Select ();
    $ S-> test ();
?>

1.2. Support delay static binding (Late Static Binding)

In PHP5, we can self keyword in the class or __CLASS__ judge or calling the current class. But there is a problem, if we are to call in the subclass, the result will be a parent. Since inheriting the parent class, static members had been bound. E.g:

class A {
    public static function who () {
        echo __CLASS__;
    }
    public static function test () {
        self :: who ();
    }
}
class B extends A {
    public static function who () {
        echo __CLASS__;
    }
}
B :: test ();

// The above code output result is: A; This is different from our expectations, we want the corresponding results for the original class.

PHP 5.3.0 adds a static keyword to refer to the current class, which implements the delay static binding:

class A {
    public static function who () {
        echo __CLASS__;
    }
    public static function test () {
        static :: who (); // here to achieve a statically bound delayed
    }
}
class B extends A {
    public static function who () {
        echo __CLASS__;
    }
}
    
B :: test ();

// Output the results of the above code is: B

1.3 supports the goto statement

Most computer programming languages are supported unconditionally turned goto statement, when the program executes the goto statement, goto statement that is shifted from the reference position indicated in the program to continue. Despite the goto statement may cause the program flow is not clear, readable weakened, but with the convenience of its unique place in certain circumstances, such as interrupts deeply nested loops and if statements.

 
    goto a;
    echo 'Foo';
    a:
    echo 'Bar';
    for ($ i = 0, $ j = 50; $ i <100; $ i ++) {
      while ($ j--) {
        if ($ j == 17) goto end;
      }
    }
    echo "i = $ i";
    end:
    echo 'j hit 17';

1.4 supports closures, Lambda / Anonymous functions

Closures (Closure) function and Lambda functions in functional programming concepts from the field. For example, JavaScript is the most common language closures and lambda functions support. In PHP, we can also create a function in your code run through create_function (). But there is one problem: function created only when running compiled without simultaneously with other code is compiled into executable code, so we can not use this execution code similar APC caching to improve the efficiency of code execution. In PHP5.3, we can use Lambda / Anonymous functions to define some temporary use (ie use disposable type) function, as array_map () / array_walk () and other callback function.

    echo preg_replace_callback ( '~ - ([a-z]) ~', function ($ match) {
        return strtoupper ($ match [1]);
    }, 'Hello-world');
    // Output helloWorld
  
    $ Greet = function ($ name)
    {
        printf ( "Hello% s \ r \ n", $ name);
    };
    $ Greet ( 'World');
    $ Greet ( 'PHP');
  
    // ... To a class
    $ Callback = function ($ quantity, $ product) use ($ tax, & $ total) {
      $ PricePerItem = constant (. __ CLASS__ ":: PRICE_" strtoupper ($ product).);
      $ Total + = ($ pricePerItem * $ quantity) * ($ tax + 1.0);
    };
    array_walk ($ products, $ callback);

1.5 Two new magic method __callStatic () and __invoke ()

PHP originally had a magic method __call (), when a method does not exist in the object code to call the magic method will be called automatically. New __callStatic () method are used only for static class methods. When attempting to call a static method in the class that does not exist, __ callStatic () magic method will be called automatically.

class MethodTest {
    public function __call ($ name, $ arguments) {
        // $ Name parameter is case sensitive
        .. Echo "calling object method '$ name'" implode ( '-', $ arguments) "\ n";
    }
    / ** PHP 5.3.0 and later versions of the class method valid * /
    public static function __callStatic ($ name, $ arguments) {
        // $ Name parameter is case sensitive
        .. Echo "static method call '$ name'" implode ( '-', $ arguments) "\ n";
    }
}
  
$ Obj = new MethodTest;
$ Obj-> runTest ( 'by calling the object');
MethodTest :: runTest ( 'static invocation'); // As of PHP 5.3.0

// Output after executing the above code as follows:
// Call the object method 'runTest' - an object by calling
// Call the static method 'runTest' - static call

When to call a function in the form of an object, __ invoke () method will be called automatically.

class MethodTest {
    public function __call ($ name, $ arguments) {
        // $ Name parameter is case sensitive
        . Echo "Calling object method '$ name'" implode ( ',', $ arguments) "\ n".;
    }
        
    / ** PHP 5.3.0 and later versions of the class method valid * /
    public static function __callStatic ($ name, $ arguments) {
        // $ Name parameter is case sensitive
        . Echo "Calling static method '$ name'" implode ( ',', $ arguments) "\ n".;
    }
}
$ Obj = new MethodTest;
$ Obj-> runTest ( 'in object context');
MethodTest :: runTest ( 'in static context'); // As of PHP 5.3.0

1.6 New Nowdoc grammar

Usage and Heredoc similar, but use single quotes. Heredoc is required to declare by the use of double quotes. Nowdoc will not do any variable resolution, very suitable for passing a PHP script.

    After single quotes // Nowdoc support PHP 5.3
    $ Name = 'MyName';
    echo <<< 'EOT'
    My name is "$ name".
    EOT;
    // The above code output My name is "$ name". ((Wherein the variables are not parsed)
    // Heredoc unquoted
    echo <<< FOOBAR
    Hello World!
    FOOBAR;
    Support after // or double quotes PHP 5.3
    echo <<< "FOOBAR"
    Hello World!
    FOOBAR;

Supported by Heredoc to initialize static variables, class members and class constants.

// Static variables
function foo ()
{
    static $ bar = <<< LABEL
Nothing in here ...
LABEL;
}
// Class members constants
class foo
{
    const BAR = <<< FOOBAR
Constant example
FOOBAR;
    
    public $ baz = <<< FOOBAR
Property example
FOOBAR;
}

1.7 outside the class can also be used to define constants with the const

// PHP constants defined in this way is usually
define ( "CONSTANT", "Hello world.");
  
// And a new way to define constants
const CONSTANT = 'Hello World';

1.8 ternary operator adds a shortcut way of writing

Originally format is (expr1) (expr2): (expr3); if expr1 result is True, it returns expr2 results?.
A writing PHP5.3 new way, you can omit the intermediate part, writing for the expr1: expr3; if expr1 result is True, then returns expr1 results?

// Original format
? $ Expr = $ expr1 $ expr1: $ expr2
// New format
$ Expr = $ expr1:? $ Expr2

1.9 HTTP status codes in the 200-399 range are considered successful visit

1.10 supports dynamic call the static method

class Test {
    public static function testgo ()
    {
        echo "gogo!";
    }
}
$ Class = 'Test';
$ Action = 'testgo';
$ Class :: $ action (); // output "gogo!"

2 PHP5.3 changed Other notable

1.1 fixes a lot of bug
1.2 PHP to improve performance
1.3 php.ini variable can be used
1.4 mysqlnd extend into the core theory of the extended access mysql rate than in previous MySQL and MySQLi fast expansion (see http://dev.mysql.com/downloads/connector/php-mysqlnd/)
1.5 ext / phar, ext / intl, ext / fileinfo, ext / sqlite3 and ext / enchant and other extensions by default with PHP bindings release. Phar PHP which can be used to package a program, similar to Java in the jar mechanism.

1.6 ereg regular expression functions are no longer available by default, please use the faster speed of the PCRE regular expression functions

3 deprecated features

PHP 5.3.0 Two new level of errors: E_DEPRECATED and E_USER_DEPRECATED error level E_DEPRECATED be used to illustrate a function or function has been deprecated E_USER_DEPRECATED level to signal that the user code deprecated feature, similar E_USER_ERROR and E_USER_WARNING.. grade.

The following is a list of instructions INI deprecated any instruction that will result in the following error E_DEPRECATED.
define_syslog_variables
register_globals
register_long_arrays
safe_mode
magic_quotes_gpc
magic_quotes_runtime
magic_quotes_sybase
Deprecated INI file with '#' at the beginning of the comment.

Deprecated functions:
call_user_method () (use call_user_func () replacement)
call_user_method_array () (use call_user_func_array () replacement)
define_syslog_variables ()
dl ()
ereg () (use preg_match () replacement)
ereg_replace () (use preg_replace () replacement)
eregi () (use preg_match () with 'i' modifier substitute)
eregi_replace () (use preg_replace () with 'i' modifier substitute)
set_magic_quotes_runtime () function and its alias magic_quotes_runtime ()
session_register () (use the $ _SESSION super all variable substitutions)
session_unregister () (use the $ _SESSION super all variable substitutions)
session_is_registered () (use the $ _SESSION super all variable substitutions)
set_socket_blocking () (use stream_set_blocking () replacement)
split () (use preg_split () replacement)
spliti () (use preg_split () with 'i' modifier substitute)
sql_regcase ()
mysql_db_query () (use mysql_select_db () and mysql_query () replacement)
mysql_escape_string () (use mysql_real_escape_string () replacement)
Waste transfer locale name as a string using the LC_ * constants series instead.
mktime () is is_dst parameters using the new timezone handling functions instead.
Deprecated features:
Deprecated the return value of new by reference distribution.
Passing by reference is deprecated call.
     
         
         
         
  More:      
 
- Build your own Git server under Linux (Server)
- Use install_updates upgrade GAMIT / GLOBK (Linux)
- JavaScript property of checkbox.disabled (Programming)
- Learning and Practice (Linux)
- sed and awk in shell usage and some examples (Linux)
- Linux to achieve a simple cp command (Linux)
- How ONLYOFFICE collaborative editing document on Linux (Linux)
- Solaris 10 nagios monitoring system (Linux)
- On the Web application attack techniques Common (Linux)
- Java integrated development environment common set of operations (Linux)
- Create a DLL using MinGW and Attention (Programming)
- How to Install Node.js in CentOS 7 (Linux)
- Shell for loop (Programming)
- Linux common network tools: hping Advanced Host Scan (Linux)
- Create a project using Android Studio LinearLayout (Programming)
- Python interview must look at 15 questions (Programming)
- Linux Demo dd IO test (Linux)
- Docker build private warehouse (Server)
- Oracle 11g on Linux system boot from the startup settings (Database)
- MySQL loose index scan (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.