469,275 Members | 1,871 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

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.
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
--------------------------------------

Jun 6 '06 #1
4 13316
Skrol29 wrote:
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?


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
Jun 6 '06 #2
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
http://www.tinybutstrong.com
------------------------------------------

Janwillem Borleffs a écrit :
Skrol29 wrote:
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?


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


Jun 6 '06 #3

Skrol29 wrote:
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
--------------------------------------


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.

Jun 6 '06 #4
Skrol29 wrote:
Hello,

It can be very usefull to code:
$obj = new stdClass;
Unfortunately the few that the documentation officially tells about
this class is:

<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/

Jun 6 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by red | last post: by
2 posts views Thread by juglesh | last post: by
4 posts views Thread by David | last post: by
5 posts views Thread by JamesG | last post: by
2 posts views Thread by Jean Marie | last post: by
1 post views Thread by electronik | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.