Hey Stu.
Well, isn't that special ;--)
Jesus, I kept echoing $this-$foo within the parent class and getting 0,
instead of 1.
You wrote your reply; I checked the results again, and, voila, it worked --
obviously I must have been missing something and corrected the mistake in my
endless trial
Hey all.
Problem:
Class test {
var $foo = 0;
function __construct() {
$this-myfunc(foo, 1);
}
function myfunc($name, $val) {
$this-$name = $val;
}
}
Now, PHP correctly evaluates $this-$name as 0; i.e. the default property
value of $this-foo.
However,
I don't know the details of your app, but you might want to reconsider a
resdesign.
Having said that, your code actually works for me. If I use your class as is,
foo is 1. That is:
$x = new test;
echo $x-foo;
outputs 1. Isn't that what you want?
Regards,
Bruce
PHP [EMAIL PROTECTED]
PHP wrote:
Problem:
Class test {
var $foo = 0;
function __construct() {
$this-myfunc(foo, 1);
}
function myfunc($name, $val) {
$this-$name = $val;
}
}
Now, PHP correctly evaluates $this-$name as 0; i.e. the default property
value of $this-foo.
However,
Sounds like a PHP version problem. PHP 4 will output 0 and PHP 5 will give
1. The constructor must be named the same as the class name in PHP 4 for
this to work.
You can have both constructors in your class so it will work in both
versions.
- Frank
I don't know the details of your app, but you
5 matches
Mail list logo