PHP Doku:: Backward Incompatible Changes - migration52.incompatible.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchAppendicesMigrating from PHP 5.1.x to PHP 5.2.xBackward Incompatible Changes

Ein Service von Reinhard Neidl - Webprogrammierung.

Migrating from PHP 5.1.x to PHP 5.2.x

<<What has changed in PHP 5.2.x

New Error Messages>>

Backward Incompatible Changes

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


6 BenutzerBeiträge:
- Beiträge aktualisieren...
goellerk at bucks dot edu
7.06.2010 23: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
4.02.2010 15: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.02.2008 3: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.01.2008 17: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.11.2007 13: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.03.2007 5: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.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)