PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm stuck on this one, and I don't know why, maybe it has something to do with PHP 5 (I've written for 4 before).
when I create an object and set the value of a particular class property, it changes all the properties. I'm sure it's something simple, but I just don't get it.
//---CREATE PROJECT-------
class pObject{
var $name;
var $start_date;
var $summary;
}
$test_pro = new pObject; //---- create the object
$test_pro->$name = "test name"; //----- set the project name property
echo $test_pro->$name; //----- returns "test-name"
$test_pro->$start_date = "date"; //----- set the project start date property
echo $test_pro->$start_date; //----- returns "date"
echo $test_pro->$name; //----PROBLEM also returns "date"
echo $test_pro->$summary; //----PROBLEM 2 this also returns "date" (as upposed to NULL)
class testclass {
var $var;
}
$var = 'hello';
$object = new testclass;
echo $object->$var; // tries to echo $object->hello, but fails since no such variable exists
// correct usage:
$object->var = 'object var';
echo $object->var; // outputs 'object var'
Thanks guys, it was the dollar signs after the "->" I knew it was something simple. Anywhoo, as far as being a class, it will have functions, but I thought better than to post the whole def.
RestoSpeed wrote:Thanks guys, it was the dollar signs after the "->" I knew it was something simple. Anywhoo, as far as being a class, it will have functions, but I thought better than to post the whole def.
-Brandon
Good job. :-p
Personally, I hate to see long snippets.