Re: Classes and Global vars
| From: | Matthew Leingang | Date: | Thu, 05 Oct 2000 18:12:19 +0000 |
| Subject: | Re: Classes and Global vars | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-18756@lists.php.net to get a copy of this message | ||
Robert,
I believe that's a very pesky incompatibility between PHP3 and PHP4. You
cannot instantiate class members to variables in the declaration. You
instead have to put it into the constructor. Viz:
$MESSAGE = "This is only a test.";
class testclass {
var $message;
function testclass() { //the constructor
GLOBAL $MESSAGE;
$this->message = $MESSAGE;
}
// etc...
}
[scrounge scrounge scrounge]
Ah, yes, here it is:
http://www.php.net/version4/incompatibilities.php
First on the list.
HTH,
Matt
----------------------------------------------------------------
Matthew Leingang http://www.math.rutgers.edu/
Rutgers University leingang@math.rutgers.edu
Department of Mathematics "This signature needs no quote."
On Wed, 4 Oct 2000, Robert Covell wrote:
> Having a heck of a time accessing vars defined in another file
> (config.php3). I am using php4.0.2 and have a simple test class.
>
> The config file:
> <?
> $MESSAGE = "Test message...";
> ?>
>
>
> The class:
> <?
> require("config.php3");
> class testclass
> {
> var $message = $MESSAGE;
>
> function print_message()
> {
> return $this->message;
> }
> }
> ?>
>
> When I do:
> <?
> $theclass=new testclass;
> echo $theclass->message;
>
> I get:
>
> Parse error: parse error in /usr/local/apache/htdocs/testclass.lib on line 6
>
> Fatal error: Cannot instantiate non-existent class: testclass in
> /usr/local/apache/htdocs/test2.php on line 5
>
>
> I have no idea why. Tried to include it, and just about everything I can
> think of and have no idea. Any ideas...
>
> -Bob
>
>
> [ Part 112: "Included Message" ]
>