note 59128 added to language.types.object
| From: | TrevorBlackbirdyurab dot com at osu1 dot php dot net | Date: | Sun, 27 Nov 2005 05:33:48 +0000 |
| Subject: | note 59128 added to language.types.object | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99168@lists.php.net to get a copy of this message | ||
You can create a new object using the built-in stdClass or by using type-casting:
<?php
// This is the proper way
$object1 = new stdClass();
// This works too
$object2 = (object) NULL;
// This will create an object from an array
$monkey_array = array('title'=>'Spider Monkey',
'src'=>'monkey.jpg');
$monkey_object = (object) $monkey_array;
print $monkey_object->title . ' ' . $monkey_object->src;
// You can type-cast in the middle of an expression
function customHTML($some_object) {
// this function expects an object as the argument and returns some output
}
print '<p>Writing some output ' . customHTML( (object) array('rows'=>3,
'cols'=>4) );
?>
----
Manual Page -- http://www.php.net/manual/en/language.types.object.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59128
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59128&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59128&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59128&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59128&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59128&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59128&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59128&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59128&report=yes
Search -- http://master.php.net/manage/user-notes.php