tags:

views:

2047

answers:

3

with a new array I do this:

$aVal = array();

$aVal[key1][var1] = "something";
$aVal[key1][var2] = "something else";

Is there a similar syntax for an object

(object)$oVal = "";

$oVal->key1->var1 = "something";
$oVal->key1->var2 = "something else";
+27  A: 
$x = new stdClass();

A comment in the manual sums it up best:

stdClass is the default PHP object. stdClass has no properties, methods or parent. It does not support magic methods, and implements no interfaces.

When you cast a scalar or array as Object, you get an instance of stdClass. You can use stdClass whenever you need a generic object instance.

zombat
Hey Zombat, nice rep count!--Ed
RibaldEddie
A: 

was looking for same answer! thanks to zombat :)

HungryCoder
A: 

php.net said it is best:

$new_empty_object = new StdClass();

HungryCoder