Re: PHP Object Constructors
| From: | Lars Torben Wilson | Date: | Fri, 15 Sep 2000 18:55:55 +0000 |
| Subject: | Re: PHP Object Constructors | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-16979@lists.php.net to get a copy of this message | ||
The Captain writes:
> I was wondering how I could pass a value to a constructor. Let's say my
> object looks like this:
>
> class openFile {
> var $filename;
> var $fp;
>
> function openFile() {
> /* filename not assigned */
> }
>
> function openFile($f) {
> $this->filename = $f;
> }
> }
>
>
> What I'm wondering is how you can pass that filename variable into the
> constructor. PHP yells when I type:
>
> $of = new openFile("/var/logs/log_file");
>
> Is this possible?
>
> Thanks in advance
Yup--what version of PHP are you using? :) PHP has had this ability
since version 3.0.3.
What, exactly, does PHP yell at you when you run the above code?
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+