File tree 1 file changed +53
-5
lines changed
1 file changed +53
-5
lines changed Original file line number Diff line number Diff line change 77
77
78
78
9. get_class() starting PHP 5 returns the name of the class as it was
79
79
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.
81
82
Example :
82
83
<?php
83
84
class FooBar {
84
85
}
86
+ class ExtFooBar extends FooBar{}
85
87
$a = new FooBar();
86
- var_dump(get_class($a));
88
+ var_dump(get_class($a), get_parent_class($a) );
87
89
?>
88
90
89
91
Output (PHP 4):
90
92
string(6) "foobar"
93
+ string(9) "extfoobar"
91
94
92
95
Output (PHP 5):
93
96
string(6) "FooBar"
97
+ string(9) "ExtFooBar"
94
98
----------------------------------------------------------------------
95
99
Example code that will break :
96
100
//....
101
105
//...
102
106
}
103
107
//...
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
106
155
107
-
You can’t perform that action at this time.
0 commit comments