Migrating from PHP 5.1.x to PHP 5.2.x
在线手册:中文 英文
PHP手册

Backward Incompatible Changes

Although most existing PHP 5 code should work without changes, you should pay attention to the following backward incompatible changes:


Migrating from PHP 5.1.x to PHP 5.2.x
在线手册:中文 英文
PHP手册
PHP手册 - N: Backward Incompatible Changes

用户评论:

goellerk at bucks dot edu (07-Jun-2010 10:20)

str_pad has been modified as well, to enforce UPPERCASE sensitivity on the pad_type declaration.

Optional argument pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. If pad_type is not specified it is assumed to be STR_PAD_RIGHT.

If entered as:
$foo = 10;
$wrong = str_pad($foo, 4,'0',str_pad_left);
print "wrong is '$wrong'<br>";

$right = str_pad($foo,4,'0',STR_PAD_LEFT);
print "right is '$right'<br>";

results:
wrong is '    '
right is '  10'

Alexander Schuch (04-Feb-2010 02:42)

If the sole reason for having "abstract static methods" is to force the implementation of such a method in a child, consider using an interface for them. The abstract class implements the interface, and a child class extends the base class and defines the "abstract static methods".

<?php
interface I
{
static public function
f();
}

abstract class
C implements I
{
// more/other methods go here
}

class
D extends C
{
static public function
f()
{
echo
'I am f().';
}
}
?>

jbarker at erepublic dot com (22-Feb-2008 02:44)

If any of your code relies on includes of URLS  à la allow_url_fopen, be aware that a new directive (allow_url_include) has been added, and that it defaults to Off.

Tachy (31-Jan-2008 04:04)

$string="12345";
$rightstring1=substr($string,-3);
$rightstring2=substr($string,-8);
echo "Result1: ".$rightstring1."<BR>";
echo "Result2: ".$rightstring2."<BR>";

PHP5.1.x:
Result1: 345
Result2: 12345

PHP5.2.x
Result1: 345
Result2: <Empty>

php dot manual at frankkleine dot de (10-Nov-2007 12:17)

Between PHP 5.2.3 and 5.2.4 another backward incompatible change was introduced: parent classes now can not access private properties of child classes with get_object_vars(). See the following example:

class Bar {
    public function dumpBar()  {
        var_dump(get_object_vars($this));
    }
}
class Foo extends Bar {
    public $public = 'public';
    protected $protected = 'protected';
    private $private = 'private';

    public function dump() {
        var_dump(get_object_vars($this));
    }
}

$foo = new Foo();
$foo->dump();
$foo->dumpBar();

The result with PHP < 5.2.4:
E:\php\tests>php get_object_vars.php
array(3) {
  ["public"]    => string(6) "public"
  ["protected"] => string(9) "protected"
  ["private"]   => string(7) "private"
}

array(3) {
  ["public"]    => string(6) "public"
  ["protected"] => string(9) "protected"
  ["private"]   => string(7) "private"
}

And the result with PHP >= 5.2.4:
E:\php-5.2.4-Win32>php ../php/tests/get_object_vars.php
array(3) {
  ["public"]    => string(6) "public"
  ["protected"] => string(9) "protected"
  ["private"]   => string(7) "private"
}

array(2) {
  ["public"]    => string(6) "public"
  ["protected"] => string(9) "protected"
}

As you can see the private property is missing now when dumped from the parent class Bar.

Erik Osterman (30-Mar-2007 03:44)

It should be noted that if you provide a __toString method, you can cast the object to a string and use it as an array key (PHP 5.2.x).

e.g.   $array[ (string)$myObject ] = 'foobar';

This is an alternative to using spl_object_hash.