oop - Simple Objects in PHP question [newbie] -
i know can create array this:
$a = array();
and append new name value pairs thus:
$a['test'] = 'my new value';
it possible omit first line, although bad practice!
i find objects easier read , understand, i've done taken array of name value pairs , cast object:
$a = (object)$a;
thus can access parameters:
$a->test;
it seems wasteful overhead of creating array start with, possible create object , somehow add name value pairs in similar way array?
thanks
yes, stdclass
class designed that.
$a = new stdclass; $a->test = 'my new value';
you can think of being akin following javascript code:
var = {}; a.test = 'my new value';
in fact, if had php code received data json, running json_decode()
on data results in stdclass
object included properties.
Comments
Post a Comment