PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of sdwrage  >  Delegate  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: An example of the usage
Class: Delegate
Manage and call closures and callback functions
Author: By
Last change:
Date: 8 years ago
Size: 1,000 bytes


Class file image Download
<?php require_once 'Delegate.php'; ?>
----------------------------------USAGE SINGLE------------------------------------
// Testing function
function test () { echo "testing";}
// Testing Class
class Dog { protected $_name = 'charlie'; public function bark () { echo $this->_name; }}
// Testing Instance
$mydog = new Dog();
// Creating Delegate to add each one individually
$processruns = new Delegate();
$processruns->add(function() { echo "hello"; });
$processruns->add(function() { echo "world"; });
$processruns->add(array($mydog, 'bark'));

----------------------------------USAGE Array------------------------------------

= new Delegate();
$processruns2->add(array(function() { echo "hello"; },
                                function() { echo
"world"; },
$mydog, 'bark'),