www.webdeveloper.com
Results 1 to 3 of 3

Thread: PHP stdClass

  1. #1
    Join Date
    Sep 2005
    Location
    Portland Oregon
    Posts
    153

    PHP stdClass

    I have a large class. The $this internal variable seems to be getting clobbered somewhere. On one line an echo "this->id=$this->id" works perfectly. The next line is a conditional statement and if that 'echo' line is inserted there it tells me that 'id' is an unknown property. Example:
    Code:
    $foo = 'bar';
    echo "this->id=$this->id";  // works greate shows 'this->id=36'
    if( isset($foo) ) {
      echo "this->id=$this->id";  // fails with unknown property 'id'
    }
    If I do a print_r of the object, I clearly see [id] = 36 listed. But I noticed at the end of the object there is an additional entry for stdClass of:
    Code:
    this:stdClass Object
    (
        [invSupplierKeys] => Array
            (
                [1] => 30011
            )
    }
    I do not do a new stdClass anywhere. Where and how can this be being created and why is it in the context of $this?

    Hope someone can shed some light....

    tony

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    This worked fine for me:
    PHP Code:
    <?php
    class Test
    {
       var 
    $id 36;
       function 
    Test()
       {
          echo 
    "this->id=$this->id";
          echo 
    "<br>";
          if(
    true)
          {
             echo 
    "this->id=$this->id";
          }
       }
    }
    $test = new Test();
    So, if you are still having a problem, we probably need to see the exact code you are using that results in this error (preferably reduced to the shortest, simplest code you can find that generates the error).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Sep 2005
    Location
    Portland Oregon
    Posts
    153
    That's the problem, it's a BIG class and I don't know how to reproduce it. This class (emailClass) extends a docTemplate class which in turn utilizes a varInfo class which uses several classes (orderClass, orderItemClass, itemOptionClass, inventoryClass, invSupplierClass, etc....)

    This just came up and I'm not sure why. I've had lots of run time on all of this without problems. All I know is that if I put the debugging output on one line (ahead of an if( isset(...) )) it's fine, but if I put it below the if() it fails...

    Makes absolutely no sense to me... Note that most all of the classes utilize a globalObjectClass which returns a reference to a common object. I.e. I do
    $Aobj =& newGlobalObject("Aclass.php"); and then maybe in a different function I do the same thing. It allows me to keep the class context rather than having separate instances of those classes.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles