php - How to use Closure as an Anonymous Function like on Javascript? -


i have question, didn't understand closures uses on oop, did this:

<?php /** * */  class xsample { public static $name;  public static $address = array("mandaluyong", "city");  public static function setname ($name) { self::$name = $name;  }  public static function getname() { echo self::$name;  }  public static function sub ($func) { return call_user_func_array($func, self::$address);  }  }  xsample::setname("eric");  xsample::sub(function ($address) { echo $address;  });  ?> 

and echo "mandaluyong". i'm expecting it'll return array xsample::$address didn't. please explain me?

call_user_func_array passes 2nd argument's elements paramters function being called. if function had parameter work.

xsample::sub(function ($address, $address2) { echo $address;  echo $address2;  });  

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -