|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I've run into an interesting issue. I am calling a static member of a
class, and passing in by reference the variable $oCust. I would like to have an object instantiatee & assigned to this variable (see code snippets below). The object is definitely being instantiated, I check right after I create it and again before the function returns. However, back in the main thread after the function returns, $oCust has not been assigned anything... Why should this be? Is there some scope issue that I'm not aware of? Thanks for looking... Tyler ================================================== ===== $oCust =NULL; .... DAL::setCust(COMPANY_ID_DEFAULT, $sUsername, $sPassword, $oCust); echo($oCust); ================================================== ===== ================================================== ===== public static function setCust($iCompanyId, $iCustId, &$oCust) { $dbHhweb =self::getCnxn(); $sQuery ="a query that does work, I checked"; $rsCust =mysql_query($sQuery, $dbHhweb); $aCustFields =mysql_fetch_array($rsCust, MYSQL_ASSOC); if($aCustFields) { $oCust =new Cust(a lotta fields); echo($oCust); $oAddrBill =new Address(more fields); $oAddrShip =new Address(more fields); $oCust->setAddrBill($oAddrBill); $oCust->setAddrShip($oAddrShip); } echo($oCust); return true; } ================================================== ===== |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Oh - missed a detail. If I change the function to return $oCust, it
does indeed return an instantiated object just fine... Tyler |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Tue, 26 Feb 2008 19:38:37 +0100, Logos <tyler.style@gmail.com> wrote:
> I've run into an interesting issue. I am calling a static member of a > class, and passing in by reference the variable $oCust. I would like > to have an object instantiatee & assigned to this variable (see code > snippets below). The object is definitely being instantiated, I check > right after I create it and again before the function returns. > However, back in the main thread after the function returns, $oCust > has not been assigned anything... > > Why should this be? Is there some scope issue that I'm not aware of? > > Thanks for looking... > > Tyler > > > ================================================== ===== > $oCust =NULL; > ... > DAL::setCust(COMPANY_ID_DEFAULT, $sUsername, $sPassword, $oCust); ---------------^1------------------^2----------^3----------^4 > ================================================== ===== > public static function setCust($iCompanyId, $iCustId, &$oCust) { ---------------------------------^1-----------^2--------^3 Where's the password? That's the one being done by reference. It doesn't matter how you name your variables when calling: Funtion = caller: $iComanyid = COMPANY_ID_DEFAULT $iCustId = $sUsername $oCust = $sPassword ....which leaves a 4th variable, with which the function does nothing, nada, so it's NULL all the way. -- Rik Wasmus |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Feb 26, 4:21 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Tue, 26 Feb 2008 19:38:37 +0100, Logos <tyler.st...@gmail.com> wrote: > > I've run into an interesting issue. I am calling a static member of a > > class, and passing in by reference the variable $oCust. I would like > > to have an object instantiatee & assigned to this variable (see code > > snippets below). The object is definitely being instantiated, I check > > right after I create it and again before the function returns. > > However, back in the main thread after the function returns, $oCust > > has not been assigned anything... > > > Why should this be? Is there some scope issue that I'm not aware of? > > > Thanks for looking... > > > Tyler > > > ================================================== ===== > > $oCust =NULL; > > ... > > DAL::setCust(COMPANY_ID_DEFAULT, $sUsername, $sPassword, $oCust); > > ---------------^1------------------^2----------^3----------^4 > > > ================================================== ===== > > public static function setCust($iCompanyId, $iCustId, &$oCust) { > > ---------------------------------^1-----------^2--------^3 > > Where's the password? That's the one being done by reference. It doesn't > matter how you name your variables when calling: > Funtion = caller: > $iComanyid = COMPANY_ID_DEFAULT > $iCustId = $sUsername > $oCust = $sPassword > ...which leaves a 4th variable, with which the function does nothing, > nada, so it's NULL all the way. > -- > Rik Wasmus Aha! Thank you for pointing out my blithering idiocy...how nice that I've managed to embarrass myself so badly in a place that is public to the entire known universe... :P |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Feb 26, 4:41pm, Logos <tyler.st...@gmail.com> wrote:
> On Feb 26, 4:21 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: > > > > > On Tue, 26 Feb 2008 19:38:37 +0100, Logos <tyler.st...@gmail.com> wrote: > > > I've run into an interesting issue. I am calling a static member ofa > > > class, and passing in by reference the variable $oCust. I would like > > > to have an object instantiatee & assigned to this variable (see code > > > snippets below). The object is definitely being instantiated, I check > > > right after I create it and again before the function returns. > > > However, back in the main thread after the function returns, $oCust > > > has not been assigned anything... > > > > Why should this be? Is there some scope issue that I'm not aware of? > > > > Thanks for looking... > > > > Tyler > > > > ================================================== ===== > > > $oCust =NULL; > > > ... > > > DAL::setCust(COMPANY_ID_DEFAULT, $sUsername, $sPassword, $oCust); > > > ---------------^1------------------^2----------^3----------^4 > > > > ================================================== ===== > > > public static function setCust($iCompanyId, $iCustId, &$oCust) { > > > ---------------------------------^1-----------^2--------^3 > > > Where's the password? That's the one being done by reference. It doesn't > > matter how you name your variables when calling: > > Funtion = caller: > > $iComanyid = COMPANY_ID_DEFAULT > > $iCustId = $sUsername > > $oCust = $sPassword > > ...which leaves a 4th variable, with which the function does nothing, > > nada, so it's NULL all the way. > > -- > > Rik Wasmus > > Aha! Thank you for pointing out my blithering idiocy...how nice that > I've managed to embarrass myself so badly in a place that is public to > the entire known universe... :P Don't worry about that. I'm sure we have done plenty idiotic things in our past. Hey, everyone's gotta start somewhere, which makes them a n00b at one point in their life, regardless of if they choose to accept it or not! |
|
![]() |
| Outils de la discussion | |
|
|