note 102445 added to functions.anonymous

[email protected] Mon, 14 Feb 2011 17:31:04 -0800
Newsgroups php.notes
Message-ID <[email protected]>
These  Closures are really interesting to me .This would be helpful.
Class Operations{
	public function ops($x,$y,$op){
		switch ($op){
			case 'ADD':return function() use($x,$y){
							return $x+$y."<br>";							
					   };
					   break;
			case 'SUB': return function() use ($x,$y){
							return $x-$y."<br>";							
						};
						break;
			default:    return function(){
							return "Operation is not supported by class"."<br>";
						};
		}			
	}
}

$op =  new Operations();
$fn1 = $op->ops(6,7,'ADD');
echo $fn1();

$fn2 = $op->ops(6,2,'SUB');
echo $fn2();

$fn2 = $op->ops(6,7,'MUL');
echo $fn2();
----
Server IP: 69.147.83.197
Probable Submitter: 75.187.148.110
----
Manual Page -- http://www.php.net/manual/en/functions.anonymous.php
Edit        -- https://master.php.net/note/edit/102445
Del: integrated  -- https://master.php.net/note/delete/102445/integrated
Del: useless     -- https://master.php.net/note/delete/102445/useless
Del: bad code    -- https://master.php.net/note/delete/102445/bad+code
Del: spam        -- https://master.php.net/note/delete/102445/spam
Del: non-english -- https://master.php.net/note/delete/102445/non-english
Del: in docs     -- https://master.php.net/note/delete/102445/in+docs
Del: other reasons-- https://master.php.net/note/delete/102445
Reject      -- https://master.php.net/note/reject/102445
Search      -- https://master.php.net/manage/user-notes.php