Connecting Tech Pros Worldwide Forums | Help | Site Map

Class variable problem

tatsudoshi
Guest
 
Posts: n/a
#1: Oct 16 '06
Hello,

I have this class http://pastebin.com/807571, where I set some variables on
__construct. Originaly I set the $total_? variables when the function
showLayout() was called. I know pastebin is having problems, so if you can't
get the code, I will upload it in plain text on my own server.
This function is called from a page object, which is called from a
controller and so on.
Doing it this way meant that all variables set during the showLayout()
function, were set to null, next time I opened the object.
Then I set it up like it is now, where I set all call variables doring
__construct and this worked fine.
But now the problem is, that the last values added to the class variables
from the showLayout() function are not added.

Is this a bug in PHP5 or am I doing something terribly wrong here?

Best regards, tatsudoshi



tatsudoshi
Guest
 
Posts: n/a
#2: Oct 16 '06

re: Class variable problem


I have uploaded the class at http://www.criion.net/class.Kurv.php.txt


Colin Fine
Guest
 
Posts: n/a
#3: Oct 16 '06

re: Class variable problem


tatsudoshi wrote:
Quote:
Hello,
>
I have this class http://pastebin.com/807571, where I set some variables on
__construct. Originaly I set the $total_? variables when the function
showLayout() was called. I know pastebin is having problems, so if you can't
get the code, I will upload it in plain text on my own server.
This function is called from a page object, which is called from a
controller and so on.
Doing it this way meant that all variables set during the showLayout()
function, were set to null, next time I opened the object.
Then I set it up like it is now, where I set all call variables doring
__construct and this worked fine.
But now the problem is, that the last values added to the class variables
from the showLayout() function are not added.
>
Is this a bug in PHP5 or am I doing something terribly wrong here?
>
Best regards, tatsudoshi
>
>
You'll need to be more explicit about what you're expecting to see, and
what you are seeing.

I thought it might be a problem with references (in PHP5 Objects are
copied by references, but arrays are not) but I can't see a place where
you're assigning to a copied array, so it doesn't appear to be that.

Colin
Jerry Stuckle
Guest
 
Posts: n/a
#4: Oct 17 '06

re: Class variable problem


tatsudoshi wrote:
Quote:
Hello,
>
I have this class http://pastebin.com/807571, where I set some variables on
__construct. Originaly I set the $total_? variables when the function
showLayout() was called. I know pastebin is having problems, so if you can't
get the code, I will upload it in plain text on my own server.
This function is called from a page object, which is called from a
controller and so on.
Doing it this way meant that all variables set during the showLayout()
function, were set to null, next time I opened the object.
Then I set it up like it is now, where I set all call variables doring
__construct and this worked fine.
But now the problem is, that the last values added to the class variables
from the showLayout() function are not added.
>
Is this a bug in PHP5 or am I doing something terribly wrong here?
>
Best regards, tatsudoshi
>
>
The real question here is - how are you opening the object? Are you
creating a second object or are you referencing the existing object.

The code you're using to access it is also very important.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
tatsudoshi
Guest
 
Posts: n/a
#5: Oct 17 '06

re: Class variable problem


This is a snip of the code from my controller. Each page has a pagecode,
from which I select a case in a switch structur. On Kurv page, it checks to
see if the object is set, and if, gets the array from the object, otherwise
it creates the array and handles all the array related things. At the end of
the case it does this snip shown.

What it is suppose to do is first check if the useraccount can order the
item the user is trying to order.
That it check to see if the object is set, this time to either add the
array, with the new item or create a Kurv object.

I save all objects in SESSION.

if($wrong_user_account) {
$output = <<<hds
<div id='generic-content'>
<p>Denne type abonnement, kan ikke bestilles med denne konto.</p>
</div
hds;
$obj_kurv_go = new GenericOutput($output);
}
elseif(isset($this->obj_kurv)) {
$this->obj_kurv->setArray($array);
if(array_key_exists("action", $_GET) && $_GET["action"] !=
"add_to_basket"
|| array_key_exists("tilbud_id", $_GET))
$this->obj_kurv->storeLinkBack($_SERVER["HTTP_REFERER"]);

$obj_kurv_go = $this->obj_kurv;
}
else {
$link_to_basket = $this->readPage(array("mapr" ="byCode",
"sql_id" ="p_kurv_liste"))->getPageId();
$link_to_bestil = $this->readPage(array("mapr" ="byCode",
"sql_id" ="p_bestil_1"))->getPageId();
$link_to_telecare = $this->readPage(array("mapr" ="byCode",
"sql_id" ="p_telecare"))->getPageId();

$this->obj_kurv = new Kurv($array, $link_to_basket);
$this->obj_kurv->storeLinkBack($_SERVER["HTTP_REFERER"]);
$this->obj_kurv->storeLinkToBestil($link_to_bestil);
$this->obj_kurv->storeLinkToTelecare($link_to_telecare);
$obj_kurv_go = $this->obj_kurv;
}
}
$contents["gen_out"] = array($obj_kurv_go);


tatsudoshi
Guest
 
Posts: n/a
#6: Oct 17 '06

re: Class variable problem


Hello,

I have this class http://pastebin.com/807571, where I set some variables on
__construct. Originaly I set the $total_? variables when the function
showLayout() was called. I know pastebin is having problems, so if you can't
get the code, I will upload it in plain text on my own server.
This function is called from a page object, which is called from a
controller and so on.
Doing it this way meant that all variables set during the showLayout()
function, were set to null, next time I opened the object.
Then I set it up like it is now, where I set all call variables doring
__construct and this worked fine.
But now the problem is, that the last values added to the class variables
from the showLayout() function are not added.

Is this a bug in PHP5 or am I doing something terribly wrong here?

Best regards, tatsudoshi

Added:
I have uploaded the class at http://www.criion.net/class.Kurv.php.txt

Added:
This is a snip of the code from my controller. Each page has a pagecode,
from which I select a case in a switch structur. On Kurv page, it checks to
see if the object is set, and if, gets the array from the object, otherwise
it creates the array and handles all the array related things. At the end of
the case it does this snip shown.

What it is suppose to do is first check if the useraccount can order the
item the user is trying to order.
That it check to see if the object is set, this time to either add the
array, with the new item or create a Kurv object.

I save all objects in SESSION.

if($wrong_user_account) {
$output = <<<hds
<div id='generic-content'>
<p>Denne type abonnement, kan ikke bestilles med denne konto.</p>
</div
hds;
$obj_kurv_go = new GenericOutput($output);
}
elseif(isset($this->obj_kurv)) {
$this->obj_kurv->setArray($array);
if(array_key_exists("action", $_GET) && $_GET["action"] !=
"add_to_basket"
|| array_key_exists("tilbud_id", $_GET))
$this->obj_kurv->storeLinkBack($_SERVER["HTTP_REFERER"]);

$obj_kurv_go = $this->obj_kurv;
}
else {
$link_to_basket = $this->readPage(array("mapr" ="byCode",
"sql_id" ="p_kurv_liste"))->getPageId();
$link_to_bestil = $this->readPage(array("mapr" ="byCode",
"sql_id" ="p_bestil_1"))->getPageId();
$link_to_telecare = $this->readPage(array("mapr" ="byCode",
"sql_id" ="p_telecare"))->getPageId();

$this->obj_kurv = new Kurv($array, $link_to_basket);
$this->obj_kurv->storeLinkBack($_SERVER["HTTP_REFERER"]);
$this->obj_kurv->storeLinkToBestil($link_to_bestil);
$this->obj_kurv->storeLinkToTelecare($link_to_telecare);
$obj_kurv_go = $this->obj_kurv;
}
}
$contents["gen_out"] = array($obj_kurv_go);


tatsudoshi
Guest
 
Posts: n/a
#7: Oct 17 '06

re: Class variable problem


Sorry for messing up the messages. I have never tryed using newsgroups
before.
Is it possible to delete a message from the group?


tatsudoshi
Guest
 
Posts: n/a
#8: Oct 17 '06

re: Class variable problem


I am not using references at all, as I have not been able to figure out how
it works in the different versions of PHP.

----- Original Message -----
From: "Colin Fine" <news@kindness.demon.co.uk>
Newsgroups: comp.lang.php
Sent: Monday, October 16, 2006 11:48 PM
Subject: Re: Class variable problem

Quote:
You'll need to be more explicit about what you're expecting to see, and
what you are seeing.
>
I thought it might be a problem with references (in PHP5 Objects are
copied by references, but arrays are not) but I can't see a place where
you're assigning to a copied array, so it doesn't appear to be that.
>
Colin

tatsudoshi
Guest
 
Posts: n/a
#9: Oct 17 '06

re: Class variable problem


Your ansewer is message Re: Class variable problem : 17-10-2006 08:42
Sorry :-/

----- Original Message -----
From: "Jerry Stuckle" <jstucklex@attglobal.net>
Newsgroups: comp.lang.php
Sent: Tuesday, October 17, 2006 4:45 AM
Subject: Re: Class variable problem
Quote:
The real question here is - how are you opening the object? Are you
creating a second object or are you referencing the existing object.
>
The code you're using to access it is also very important.
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Jerry Stuckle
Guest
 
Posts: n/a
#10: Oct 17 '06

re: Class variable problem


tatsudoshi wrote:
Quote:
Sorry for messing up the messages. I have never tryed using newsgroups
before.
Is it possible to delete a message from the group?
>
>
No, you can't delete a message from a newsgroup. It's on hundreds of
servers all over the world.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Jerry Stuckle
Guest
 
Posts: n/a
#11: Oct 17 '06

re: Class variable problem


tatsudoshi wrote:
Quote:
----- Original Message -----
From: "Jerry Stuckle" <jstucklex@attglobal.net>
Newsgroups: comp.lang.php
Sent: Tuesday, October 17, 2006 4:45 AM
Subject: Re: Class variable problem
>
>
Quote:
>>The real question here is - how are you opening the object? Are you
>>creating a second object or are you referencing the existing object.
>>
>>The code you're using to access it is also very important.
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================
>
>
Your ansewer is message Re: Class variable problem : 17-10-2006 08:42
Sorry :-/
>
>
(Top posting fixed)

Sorry, I don't see where you're showing the code you use to save and
restore the object. You indicate you're using the session, but that's
all. What's the actual code you're using?

This would be a lot easier if you could create a simplified case where
we could see exactly what you're trying to do. It's very difficult to
go through hundreds of lines of code to understand what someone else is
doing in a few minutes of spare time :-)

Also, a couple of tips. Please don't top post - this newsgroup uses
bottom posting (like this) or inline posting (responses mixed in and
immediately after the question) as a standard.

Also - I found the message you referenced. But I'm in a different time
zone. To me your message was posted at 2:42 AM.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
tatsudoshi
Guest
 
Posts: n/a
#12: Oct 17 '06

re: Class variable problem



"Jerry Stuckle" <jstucklex@attglobal.netskrev i en meddelelse
news:QYGdnYNb7bJeKanYnZ2dnUVZ_uqdnZ2d@comcast.com. ..
Quote:
tatsudoshi wrote:
Quote:
>----- Original Message -----
>From: "Jerry Stuckle" <jstucklex@attglobal.net>
>Newsgroups: comp.lang.php
>Sent: Tuesday, October 17, 2006 4:45 AM
>Subject: Re: Class variable problem
>>
>>
Quote:
>>>The real question here is - how are you opening the object? Are you
>>>creating a second object or are you referencing the existing object.
>>>
>>>The code you're using to access it is also very important.
>>>
>>>--
>>>==================
>>>Remove the "x" from my email address
>>>Jerry Stuckle
>>>JDS Computer Training Corp.
>>>jstucklex@attglobal.net
>>>==================
>>
>>
>Your ansewer is message Re: Class variable problem : 17-10-2006 08:42
>Sorry :-/
>>
>>
(Top posting fixed)
>
Sorry, I don't see where you're showing the code you use to save and
restore the object. You indicate you're using the session, but that's
all. What's the actual code you're using?
>
This would be a lot easier if you could create a simplified case where we
could see exactly what you're trying to do. It's very difficult to go
through hundreds of lines of code to understand what someone else is doing
in a few minutes of spare time :-)
>
Also, a couple of tips. Please don't top post - this newsgroup uses
bottom posting (like this) or inline posting (responses mixed in and
immediately after the question) as a standard.
>
Also - I found the message you referenced. But I'm in a different time
zone. To me your message was posted at 2:42 AM.
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
I see. Thanks for the tips. I will make a simple example when I get home :-)


Colin Fine
Guest
 
Posts: n/a
#13: Oct 18 '06

re: Class variable problem


tatsudoshi wrote:
Quote:
----- Original Message -----
From: "Colin Fine" <news@kindness.demon.co.uk>
Newsgroups: comp.lang.php
Sent: Monday, October 16, 2006 11:48 PM
Subject: Re: Class variable problem
>
>
Quote:
>You'll need to be more explicit about what you're expecting to see, and
>what you are seeing.
>>
>I thought it might be a problem with references (in PHP5 Objects are
>copied by references, but arrays are not) but I can't see a place where
>you're assigning to a copied array, so it doesn't appear to be that.
>>
>Colin
>
>
(top-posting corrected)
Quote:
I am not using references at all, as I have not been able to figure
out how
Quote:
it works in the different versions of PHP.
>
No, I can see you aren't, and as far as I can see there is nowhere in
the code you posted where you should be.

If you had anything like

$row = $this->array[$index]

and then

$row[] = 2;

then you would need to make $row a reference otherwise the assignment to
a member of row would be to a copy and not to the original in $this->array.
This is true in both PHP4 and PHP5; but if the contents of
$this->array[$index] were itself an object (rather than an array), then
you would need to use a reference in PHP4, but not in PHP5.

You still haven't told us, AFAICS, precisely what result you are getting
and how it differs from what you expect.

Colin
Rik
Guest
 
Posts: n/a
#14: Oct 18 '06

re: Class variable problem


Jerry Stuckle wrote:
Quote:
tatsudoshi wrote:
Quote:
>Sorry for messing up the messages. I have never tryed using
>newsgroups before.
>Is it possible to delete a message from the group?
>>
>>
>
No, you can't delete a message from a newsgroup. It's on hundreds of
servers all over the world.
Well, you can try to cancel the message, which will work with significant
delay on some servers, and then only for the users that haven't downloaded
it already. Confusion all around, it's a marvelous thing.

Grtz,
--
Rik Wasmus


Jerry Stuckle
Guest
 
Posts: n/a
#15: Oct 18 '06

re: Class variable problem


Rik wrote:
Quote:
Jerry Stuckle wrote:
>
Quote:
>>tatsudoshi wrote:
>>
Quote:
>>>Sorry for messing up the messages. I have never tryed using
>>>newsgroups before.
>>>Is it possible to delete a message from the group?
>>>
>>>
>>
>>No, you can't delete a message from a newsgroup. It's on hundreds of
>>servers all over the world.
>
>
Well, you can try to cancel the message, which will work with significant
delay on some servers, and then only for the users that haven't downloaded
it already. Confusion all around, it's a marvelous thing.
>
Grtz,
Rik,

Unfortunately, very few servers process cancel requests any more. It's
too easy to fake it and cancel someone else's post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Rik
Guest
 
Posts: n/a
#16: Oct 18 '06

re: Class variable problem


Jerry Stuckle wrote:
Quote:
Rik,
>
Unfortunately, very few servers process cancel requests any more.
It's
too easy to fake it and cancel someone else's post.
True, the last time I saw it it only worked on a local (restricted) server
here.

Still, it was a great source of fun to witness the confusion after
cancelled posts, where half the users missed a post the other half had
already seen. Fortunately (*ahum*) the nntp servers I use now are a little
buggy, so I'm sure to miss some posts regardless....

Grtz,
--
Rik Wasmus


Closed Thread