Can someone tell me why I cannot write a class as follows
<?php
class Foo
{
?>
<?php
function bar() {
print "bar";
}
}
?>
I think it’s the same as
<?php
class Foo
{
function bar() {
print "bar";
}
}
?>
I suppose it’s because of this (quoting the Instruction separation section of the manual) :
This means that your code :
Is the same as :
Which explains the error you get :
EDIT : Thinking a bit more about it, I thought that this was strange, considering I often use stuff like this in my templates files :
So I tried this :
And it works perfectly fine. OK…
Now, let’s try adding the
;, like?>is supposed to do :This is working fine too, and I get the following output :
And, if changing the condition, just to be sure :
Gives no output, and not error.
Considering the sentence I quoted earlier, this is not so surprising… But, still, I’m surprised anyway ^^