Question regarding variable scope, static class functions, and passby reference

This is a discussion on Question regarding variable scope, static class functions, and passby reference within the PHP Language forums, part of the PHP Programming Forums category; I've run into an interesting issue. I am calling a static member of a class, and passing in by ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008
Logos
 
Posts: n/a
Default Question regarding variable scope, static class functions, and passby reference

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;
}
================================================== =====
Reply With Quote
  #2 (permalink)  
Old 02-26-2008
Logos
 
Posts: n/a
Default Re: Question regarding variable scope, static class functions, andpass by reference

Oh - missed a detail. If I change the function to return $oCust, it
does indeed return an instantiated object just fine...

Tyler
Reply With Quote
  #3 (permalink)  
Old 02-26-2008
Rik Wasmus
 
Posts: n/a
Default Re: Question regarding variable scope, static class functions, and pass by reference

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
Reply With Quote
  #4 (permalink)  
Old 02-26-2008
Logos
 
Posts: n/a
Default Re: Question regarding variable scope, static class functions, andpass by reference

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
Reply With Quote
  #5 (permalink)  
Old 02-26-2008
coolhand2@gmail.com
 
Posts: n/a
Default Re: Question regarding variable scope, static class functions, andpass by reference

On Feb 26, 4:41*pm, 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!
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:10 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0