RE: [PHP4BETA] A quick clarification question about PHP4...
| From: | Samuel Liddicott | Date: | Tue, 31 Aug 1999 15:01:42 +0000 |
| Subject: | RE: [PHP4BETA] A quick clarification question about PHP4... | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-3908@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Scott Stevenson [mailto:scott@maxify.com]
> Sent: Tuesday, August 31, 1999 11:58 AM
> To: php4beta@lists.php.net
> Subject: Re: [PHP4BETA] A quick clarification question about PHP4...
>
> Oh, okay. I see. So even though this works in PHP3...
>
> class myClass {
> function myClass($name) {
> $this->myVar = "Hello, $name!";
> }
> }
>
> >>$name = "Scott";
> $myInstance = new myClass($name);
> echo $myInstance->myVar;
>
> ...it does not/will not work in PHP4?
>
> If so, that sucks.
You've got the wrong idea; its not that bad!
What you can't do in php4 is:
class myClass {
$this->myVar = "Hello, $GLOBALNAME!";
function myClass($name) {
...
}
}
because the value of "Hello, $GLOBALNAME!" isn't known at parse time.
As also you can do
function x($a="a") {
to set a default parameter, you can't do
function x($a=$DEFAULTA) {
because the value of $DEFAULTA is not know at compile time.
[or at least you can and many people do at the moment, but they'll have to
check and re-write all their code before they move to php4]
As Jim so rightly says, if he knew what the default value was going to be he
probably wouldn't need to pass it as a parameter.