PHP Classes

File: defer-example.php

Recommend this page to a friend!
  Classes of Ralf Mike Pretzlaw   Defer   defer-example.php   Download  
File: defer-example.php
Role: Example script
Content type: text/plain
Description: Exmaples
Class: Defer
Defer executing of code to emulate final functions
Author: By
Last change:
Date: 12 years ago
Size: 380 bytes
 

Contents

Class file image Download
<?php

require_once 'Defer.php';

function
foo() {
   
$bar = "some-handle";

   
$defer = new Defer();
   
$defer->nullify($bar);

    echo
$bar . PHP_EOL;
}

foo();

function
baz(&$x) {

   
$defer = new Defer();
   
$defer->run(function () use(&$x) {
            echo
" rocks!" . PHP_EOL;
           
$x = null;
        });

    echo
$x;
}

$x = "defer";
baz($x);
var_dump($x);