PHP Classes

File: Example.php

Recommend this page to a friend!
  Classes of Abraham Cruz Sustaita   PHP Anonymous Function use keyword   Example.php   Download  
File: Example.php
Role: Example script
Content type: text/plain
Description: Example
Class: PHP Anonymous Function use keyword
Call functions dynamically added to objects
Author: By
Last change:
Date: 11 years ago
Size: 225 bytes
 

Contents

Class file image Download
<?php
include_once "Core/Std.php";
$new = new Core_Std;
$new->c = 3;
$new->sum = function($a, $b) use ($new) {
    return
$a + $b + $new->c;
};

$total = $new->sum(1,2);
echo
$total; // This will print 6 ( 1 + 2 + 3)