PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Sep 23, 2018 4:22 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: What's wrong here...
PostPosted: Sat Jul 30, 2005 2:54 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Aug 16, 2002 8:57 am
Posts: 1834
Location: Watertown, MA
This test passes:
Syntax: [ Download ] [ Hide ]
function TestRegistrySingeleton() {

    $this->assertReference(Registry::instance(),

                           Registry::instance());

  }

this one fails
Syntax: [ Download ] [ Hide ]
function setUp() {

    $this->testReg = Registry::instance();

  }



  function TestRegistrySingeleton() {

    $this->assertReference($this->testReg,

                           Registry::instance());

  }


with
Syntax: [ Download ] [ Hide ]
Fail: /usr/local/CIB/main-dev/compinabox/tests/unit-tests/classes/All.php ->
  All Class Tests -> /usr/local/CIB/main-dev/compinabox/tests/unit-tests/classes/Registry/All.php ->
    All Registry Tests -> /usr/local/CIB/main-dev/compinabox/tests/unit-tests/classes/Registry/BasicRegistryTests.php ->
        Registry -- Interface ->
            testregistrysingeleton ->
                       їObject: of registry] and
                      їObject: of registry] should reference the same object at line ї33]



The relevant bit of production code
Syntax: [ Download ] [ Hide ]
function &instance() {

    static $theInstance=false;

    if (!$theInstance) $theInstance = new Registry();

    return $theInstance;

  }


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 30, 2005 8:54 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
I'm going to guess you are running php4, in which case the assignment coming out of Registry::Instance() is turned into the value and not a reference.


Top
 Profile  
 
 Post subject: [Solved]
PostPosted: Sat Jul 30, 2005 8:57 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Aug 16, 2002 8:57 am
Posts: 1834
Location: Watertown, MA
Yup, I had thought tought that ampersand in the function prototype would have taken care of that. Adding the ampersand on the receiving end fixed it.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 31, 2005 12:12 pm 
Offline
DevNet Master

Joined: Thu Jan 30, 2003 9:26 pm
Posts: 2893
Location: Glasgow, Scotland
There's a problem with storing references in static variables - you'll need to use an array http://www.sitepoint.com/forums/showthread.php?t=265748


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 31, 2005 12:19 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Aug 16, 2002 8:57 am
Posts: 1834
Location: Watertown, MA
That's weird. I got it to work without using the array, and I think I ran the same test cases as Jason shows that should cause it to fail, but it didn't. But I'll switch it over anyways, just in case.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group