PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Question regarding variable scope, static class functions, and passby reference
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Question regarding variable scope, static class functions, and passby reference

Réponse
 
LinkBack Outils de la discussion
Vieux 26/02/2008, 18h38   #1
Logos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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;
}
================================================== =====
  Réponse avec citation
Vieux 26/02/2008, 18h41   #2
Logos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 26/02/2008, 23h21   #3
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 26/02/2008, 23h41   #4
Logos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 26/02/2008, 23h51   #5
coolhand2@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Question regarding variable scope, static class functions, andpass by reference

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!
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17743 seconds with 13 queries