This is sort of tied in with the question I asked earlier. Let me know
if I'm going insane, because I could swear classes are supposed to work
this way in other languages.
Let's say we have class Counter. It's declared like this.
class Counter
{
var $counter = 0;
function count()
{
$this->counter++;
}
}
//and class Test
class Test
{
function tester($counter ) // receives counter object
{
$counter->count();
}
}
//Now, let's say in the main part of the program it works like this:
$counter = new Counter();
$test = new Test();
echo $counter->counter; // should echo 0, does print out 0
$test->tester($counte r);
echo $counter->counter; // should echo 1, actually prints out 0
Why doesn't this work? I'm sure it works in C#. If this is the way it's
supposed to work in PHP, I believe it's fairly silly. Is there a way to
hack it into working? I suppose I could use globals, but I'd really
rather not. Does PHP5 change this?
Thanks
~ sock
if I'm going insane, because I could swear classes are supposed to work
this way in other languages.
Let's say we have class Counter. It's declared like this.
class Counter
{
var $counter = 0;
function count()
{
$this->counter++;
}
}
//and class Test
class Test
{
function tester($counter ) // receives counter object
{
$counter->count();
}
}
//Now, let's say in the main part of the program it works like this:
$counter = new Counter();
$test = new Test();
echo $counter->counter; // should echo 0, does print out 0
$test->tester($counte r);
echo $counter->counter; // should echo 1, actually prints out 0
Why doesn't this work? I'm sure it works in C#. If this is the way it's
supposed to work in PHP, I believe it's fairly silly. Is there a way to
hack it into working? I suppose I could use globals, but I'd really
rather not. Does PHP5 change this?
Thanks
~ sock
Comment