is stdClass officially supported by PHP ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Skrol29

    #1

    is stdClass officially supported by PHP ?

    Hello,

    It can be very usefull to code:
    $obj = new stdClass;
    Unfortunately the few that the documentation officially tells about
    this class is:
    *************** ***************
    The name stdClass is used internally by Zend and is reserved. You
    cannot have a class named stdClass in PHP.
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.

    *************** ***************

    It seems that some Pear packages instanciate this class.
    But should we do the same for code intended for public releases?

    --------------------------------------
    Skrol29

    --------------------------------------

  • Janwillem Borleffs

    #2
    Re: is stdClass officially supported by PHP ?

    Skrol29 wrote:[color=blue]
    > Unfortunately the few that the documentation officially tells about
    > this class is:
    > *************** ***************
    > The name stdClass is used internally by Zend and is reserved. You
    > cannot have a class named stdClass in PHP.
    > http://www.php.net/manual/en/language.oop.php
    > *************** ***************
    >
    > It seems that some Pear packages instanciate this class.
    > But should we do the same for code intended for public releases?
    >[/color]

    This just means you cannot do:

    class stdClass {}

    But can savely do:

    $foo = new stdClass;

    Another example:

    $obj = (object) null;
    print is_a($obj, 'stdClass') ? 1 : 0;

    Or:

    $obj = (object) null;
    print $obj instanceof stdClass ? 1 : 0;

    Both print 1...


    JW


    Comment

    • Skrol29

      #3
      Re: is stdClass officially supported by PHP ?

      Thanks Janwillem,

      It seems that :
      $obj = (object) null;
      is documented, but the equivalent :
      $obj = new clsClass;
      is not documented, except in the examples provided under the doc.
      clsClass is just mentioned to be a special class name but usage is not
      described. Which maybe means it can change in the future.

      ------------------------------------------
      Skrol29

      ------------------------------------------

      Janwillem Borleffs a écrit :
      [color=blue]
      > Skrol29 wrote:[color=green]
      > > Unfortunately the few that the documentation officially tells about
      > > this class is:
      > > *************** ***************
      > > The name stdClass is used internally by Zend and is reserved. You
      > > cannot have a class named stdClass in PHP.
      > > http://www.php.net/manual/en/language.oop.php
      > > *************** ***************
      > >
      > > It seems that some Pear packages instanciate this class.
      > > But should we do the same for code intended for public releases?
      > >[/color]
      >
      > This just means you cannot do:
      >
      > class stdClass {}
      >
      > But can savely do:
      >
      > $foo = new stdClass;
      >
      > Another example:
      >
      > $obj = (object) null;
      > print is_a($obj, 'stdClass') ? 1 : 0;
      >
      > Or:
      >
      > $obj = (object) null;
      > print $obj instanceof stdClass ? 1 : 0;
      >
      > Both print 1...
      >
      >
      > JW[/color]

      Comment

      • Chung Leong

        #4
        Re: is stdClass officially supported by PHP ?


        Skrol29 wrote:[color=blue]
        > Hello,
        >
        > It can be very usefull to code:
        > $obj = new stdClass;
        > Unfortunately the few that the documentation officially tells about
        > this class is:
        > *************** ***************
        > The name stdClass is used internally by Zend and is reserved. You
        > cannot have a class named stdClass in PHP.
        > http://www.php.net/manual/en/language.oop.php
        > *************** ***************
        >
        > It seems that some Pear packages instanciate this class.
        > But should we do the same for code intended for public releases?
        >
        > --------------------------------------
        > Skrol29
        > http://www.tinybutstrong.com
        > --------------------------------------[/color]

        Not that I'm aware of. I vaguely remember that it was called something
        else in PHP 3, something like phpStdClass.

        It's probably better to let the object autovivicate.

        Comment

        • R. Rajesh Jeba Anbiah

          #5
          Re: is stdClass officially supported by PHP ?

          Skrol29 wrote:[color=blue]
          > Hello,
          >
          > It can be very usefull to code:
          > $obj = new stdClass;
          > Unfortunately the few that the documentation officially tells about
          > this class is:[/color]
          <snip>

          IIRC, it's a base PHP class. It is usually used to stuff properties:
          $config = new stdClass;
          $config->name = 'Foo site';
          $config->db = 'foo';

          --
          <?php echo 'Just another PHP saint'; ?>
          Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

          Comment

          Working...