WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML


TUTORIALS PYTHONPHP7JAVA
JAVA
 

PHP 7 - Closure:: call()


PHP 7, above method is replaced by closure ‘call’ method.


Example

<?php
class B {
 private $y = 2;   
}
// php 7+ code,defien
$value = function(){
    return $this->y;
    
};

print($value->call(new B));


?>


Result 2
Run example »




Example

<?php
   class B {
      private $y = 7;
   }

   // Define a closure Pre PHP 7 code
   $getValue = function() {
      return $this->y;
   };

   // Bind a clousure
   $value = $getValue->bindTo(new B, 'B'); 

   print($value());
?>

Result 7
Run example »