Re: classes in php5
| From: | Maciek Ruckgaber Bielecki | Date: | Tue, 28 Sep 2004 20:15:08 +0000 |
| Subject: | Re: classes in php5 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198119@lists.php.net to get a copy of this message | ||
you are just missing the (); it wont work either in php4 or php5 that
way.
$className = "Foo";
$fooInstance = new $className();
Cheers
On Tue, Sep 28, 2004 at 01:46:27PM -0600, Daniel Watrous wrote:
> Hello all,
>
> I have a class Foo. In PHP4 I could create an instance of Foo in the following manner:
> $className = "Foo";
> $fooInstance = new $className;
>
> This would yield the same result as:
> $fooInstance = new Foo;
>
> In my efforts to port this over to PHP5 I am having trouble. Not only do I not get back an
> instance of my Foo class, but the script execution stops entirely without so much as a warning. Is
> this a bug? Is there a new mechanism in PHP5, such as a getInstance function (i.e. object
> getInstance (string className))? Thanks in advance for any comments!
>
> Daniel
--
Maciek Ruckgaber Bielecki
"The wireless telegraph is not difficult to understand. The ordinary telegraph is like a very
long cat. You pull the tail in New York, and it meows in Los Angeles. The wireless is the same, only
without the cat. "
--Albert Einstein--