How to create stdClass (Object)

function myFunction($stdObj){
 echo $stdObj->name."";
}

$a= new stdClass;
$a->name = "Ramesh Song";
$a->email = "ilovephp@gmail.com";
$a->web = "phpbuddy.blogsport.com";

myFunction($a); // output : Ramesh Song

/********  Other Way ********/

$b = array(
   "name" => "Ramesh song",
   "email" => "ilovephp@gmail.com",
   "web" => "phpbuddy.blogsport.com");

$b = (object) $b;

myFunction($b); // output : Ramesh Song

How to use array_map() with class method?

class MyClass {
 public function __construct(){}

 protected function convertToObject($array){
  return (object) $array;
 }

 public function convertMyArray($array){
  $obj = array_map(array('MyClass','convertToObject'),$array);
  return $obj;
 }
}

$array = array(
 array('Country' => 'US'),
 array('Country' => 'KOREA'),
 array('Country' => 'JAPAN'),
 array('Country' => 'INDIA'),
 array('Country' => 'CANADA')
);

$cls = new MyClass();
$obj = $cls->convertMyArray($array);
echo $obj[0]->Country; // OUTPUT : US

How to use PHP temporary file ?

$temp = tmpfile();
fwrite($temp,'Line #1'.chr(13).chr(10));
fwrite($temp,'Line #2'.chr(13).chr(10));
fwrite($temp,'Line #3'.chr(13).chr(10));
fseek($temp,0); //move file pointer

// char(13) = \r
// char(10) = \n

while($row = fgets($temp,1024)){
 echo $row ."
";
}

fclose($temp); // remove temporary fileand no space!

Output ::
Line #1
Line #2
Line #3

Access parent’s parent variable and Access interface constant variable

// Access parent's parent variable
class Parent1 {
 const PARENT_NAME = "ramesh Song";
 const PARENT_AGE = "31";
 const PARENT_EMAIL = "ilovephp@gmail.com";
 protected $_normal_val = "HeHeHeHe";
}

class Parent2 extends Parent1 {
 public function __construct(){}
}

class Child extends Parent2 {
 public function __construct(){}

 public function getParentName(){
  return parent::PARENT_NAME;
 }

 public function getNormalVal(){
  return $this->_normal_val;
 }
}

$c = new Child();
echo $c->getParentName();
echo "br";
echo $c->getNormalVal();

/*
Output :
 ramesh Song
 HeHeHeHe
*/

// Access interface constant variable

interface Parent3 {
 const PARENT_NAME = "ramesh Song";
 const PARENT_AGE = "31";
 const PARENT_EMAIL = "ilovephp@gmail.com";
 //protected $_normal_val = "HeHeHeHe"; Error : Interfaces may not include member variables
}

class Parent4 implements Parent3 {
 public function __construct(){}

 public function getParentName(){
  //return parent::PARENT_NAME;  Error : current class scope has no parent
  return self::PARENT_NAME;
 }
}

class Child2 extends Parent4 {
 public function __construct(){}

 public function getParentName(){
  return parent::PARENT_NAME;

 }
 public function getParentAge(){
  return parent::PARENT_AGE;
 }
}

$d = new Parent4();
echo $d -> getParentName();
echo "br";
$e = new Child2();
echo $e->getParentName();
echo "br";
echo $e->getParentAge();

/*
Output :
 ramesh Song
 ramesh Song
 31
*/