Skip to content

Commit b8b1b35

Browse files
committed
new incompatibilities. maybe someone from the doc group will update the
migrating guide. also Derick may add new slides to his talk :)
1 parent 1d913a9 commit b8b1b35

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

Diff for: README.PHP4-TO-PHP5-THIN-CHANGES

+53-5
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,24 @@
7777

7878
9. get_class() starting PHP 5 returns the name of the class as it was
7979
declared which may lead to problems in older scripts that rely on
80-
the previous behaviour - the class name is lowercased.
80+
the previous behaviour - the class name is lowercased. Expect the
81+
same behaviour from get_parent_class() when applicable.
8182
Example :
8283
<?php
8384
class FooBar {
8485
}
86+
class ExtFooBar extends FooBar{}
8587
$a = new FooBar();
86-
var_dump(get_class($a));
88+
var_dump(get_class($a), get_parent_class($a));
8789
?>
8890

8991
Output (PHP 4):
9092
string(6) "foobar"
93+
string(9) "extfoobar"
9194

9295
Output (PHP 5):
9396
string(6) "FooBar"
97+
string(9) "ExtFooBar"
9498
----------------------------------------------------------------------
9599
Example code that will break :
96100
//....
@@ -101,7 +105,51 @@
101105
//...
102106
}
103107
//...
104-
Possible solution is to search for get_class() in all your scripts and
105-
use strtolower().
108+
Possible solution is to search for get_class() and get_parent_class() in
109+
all your scripts and use strtolower().
110+
111+
10. get_class_methods() returns the names of the methods of a class as they
112+
declared. In PHP4 the names are all lowercased.
113+
Example code :
114+
<?php
115+
class Foo{
116+
function doFoo(){}
117+
function hasFoo(){}
118+
}
119+
var_dump(get_class_methods("Foo"));
120+
?>
121+
Output (PHP4):
122+
array(2) {
123+
[0]=>
124+
string(5) "dofoo"
125+
[1]=>
126+
string(6) "hasfoo"
127+
}
128+
Output (PHP5):
129+
array(2) {
130+
[0]=>
131+
string(5) "doFoo"
132+
[1]=>
133+
string(6) "hasFoo"
134+
}
135+
136+
11. Assignment $this is impossible. Starting PHP 5.0.0 $this has special
137+
meaning in class methods and is recognized by the PHP parser. The latter
138+
will generate a parse error when assignment to $this is found
139+
Example code :
140+
<?php
141+
class Foo {
142+
function assignNew($obj) {
143+
$this = $obj;
144+
}
145+
}
146+
$a = new Foo();
147+
$b = new Foo();
148+
$a->assignNew($b);
149+
echo "I was executed\n";
150+
?>
151+
Output (PHP 4):
152+
I was executed
153+
Output (PHP 5):
154+
PHP Fatal error: Cannot re-assign $this in /tmp/this_ex.php on line 4
106155

107-

0 commit comments

Comments
 (0)