![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() |
PHP4 OOP Problem
I'm extremely confused, using PHP 4 i have set up a class named example with a constructor function inside of it to assign values to the class variables which are equal to NULL after execution and then there is an added variable NULL which is equal to the last value assigned to one of the class variables.
Here is the code i'm using, and the output it gives. <?php
class example {
var $test, $test1, $test2;
function example($sw) {
switch($sw) {
case 1:
$this->$test = "1";
$this->$test1 = "2";
$this->$test2 = "3";
break;
case 2:
$this->$test = "2";
$this->$test1 = "3";
$this->$test2 = "1";
break;
case 3:
$this->$test = "3";
$this->$test1 = "1";
$this->$test2 = "2";
break;
default:
die("Error");
break;
}
}
}
$test = array(
new example(1),
new example(2),
new example(3)
);
var_dump($test);
?> array(3) {
[0]=>
object(example)(4) {
["test"]=>
NULL
["test1"]=>
NULL
["test2"]=>
NULL
[""]=>
string(1) "3"
}
[1]=>
object(example)(4) {
["test"]=>
NULL
["test1"]=>
NULL
["test2"]=>
NULL
[""]=>
string(1) "1"
}
[2]=>
object(example)(4) {
["test"]=>
NULL
["test1"]=>
NULL
["test2"]=>
NULL
[""]=>
string(1) "2"
}
}
__________________
|
|
|
|
|
|
#2 |
|
Programmer
Join Date: May 2005
Location: England
Posts: 61
Rep Power: 4
![]() |
Address class variables inside your class as:
$this->var_name and not: $this->$var_name That should fix your problem.
__________________
http://www.nuticulus.net/hackmysig/sig.PNG Give my site a chance, you know you want to ;-) Google will solve 99% of your problems. Including those with your sex life. Caution, may <strike>contain</strike> be nuts. |
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
isnt OO better used in PHP5?
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity." - Albert Einstein |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|