Asked 7 years ago
28 Dec 2016
Views 1388

posted

how to define inline class in php ?

dont know more about the PHP but experimenting with class. i read that stdclass is the standard class definition in PHP. so i used like this

$sound=  stdclass { 
    var d=array("i","am","sound");
};


and it give me Parse error , so what should be good way to define class inline in php

Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

i dont know where you read it but its not correct way of defining class in php


class newclass{
   var $newVar =array("i","am","good","music");
}
$new =new newclass();
echo end($new->newVar);
 

you can use class clause to define the class with his name
and new is keyword to define object of the class.
Post Answer