Re: [PHP4BETA] Classes broken?
| From: | Chad | Date: | Mon, 15 Nov 1999 16:36:38 +0000 |
| Subject: | Re: [PHP4BETA] Classes broken? | ||
| References: | 1 2 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-6250@lists.php.net to get a copy of this message | ||
Mark Constable wrote:
> Me too ! At worst, a "convention" of always passing in the
> first arg to a method to be the class label would be an ugly
> workaround. The PHPLIB people use "var $classname=suchnsuch;"
> and this could be passed as the first arg into all other class
> and method calls... ick!... help!
See my other message.
> Also, I would expect/like an included file within a class to be
> included into the context of that class but it's not, it's included
> in the context of the parent program.
>
> class Classx
> {
> include "some.inc";
> }
This should produce a parse error... Classes can contain functions and
variables, trying to include a file in a class won't work... You can
include it in a function however, and the proper way to do this would be...
<?
class Classx {
var $somevar;
function Classx() { //constructor or call a loadDefaults type method
include "some.inc";
}
...
}
// some.inc
<?
$this->somevar = "whatever";
?>
Or if you have some global configuration options that need to be
available to normal scripts and classes, do:
function Classx {
var $somevar;
function Classx() {
include "some.inc";
$this->somevar = $somevar;
}
}
//some.inc
<?
$somevar = "whatever";
?>