|
|
|
|
|
by LnxPrgr3
5094 days ago
|
|
Sure, but you defined ptr outside of the loop. Who defined $object outside of the loop in the PHP example? Also note that, in C, you have to explicitly dereference pointers: ptr = 42;
You should get a warning from your compiler if you try that. PHP effectively goes ahead and changes it to: *ptr = 42;
Perl requires you to explicitly dereference references as well: @array = ('c', 'c++', 'java', 'perl');
$item = \$array[3];
$item = 'php'; # Does NOT replace the item in the array
foreach $item (@array) {
print $item . "\n";
}
PHP is weird in this regard: if you ever assign a reference to a variable, later assignments go through that reference automatically. To convert the variable back to a normal variable, you have to unset it. I don't know of another language that acts like this. Can you think of one?Combine that with the lack of block scope, and you get surprises like the example BadCRC linked. |
|