Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Closure::call()

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 92
    Comment on it

    Welcome to Findnerd. Today we are going to disccus two new features introduces in PHP7 that are closure::call. You can bind the outer function in class. It is also known as temporarily binding an object scope to a closure and invoking it. Please have a look.

    <?php
    class Emp
    {
    protected $emp_id;
    public function getEmp(){
    return $this->emp_id;
    }
    public function Emp($emp_id){
    $this->emp_id = $emp_id;
    }
    }
    $emp1 = Emp(233);
    $emp2 = Emp(213);
    $salaryinfo = function($com_id) { 
    echo $this->getEmp() . ' ' . $com_id;
    // You can get the salary with the help of employee id and company id
      }
      $salaryinfo->call($emp1,3);
      $salaryinfo->call($emp2,5);
    ?>
    

    In above example we created a class named Emp and also created one constructor, one function named getEmp. We created two instance of the class and created a closure to reteive the salary from database. Hope this helps.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: