Created
October 8, 2013 15:33
-
-
Save asm89/6886578 to your computer and use it in GitHub Desktop.
TIL: Nested functions in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class NestedFunctions | |
{ | |
public function fn1() | |
{ | |
function nested_fn() { echo 'yay' . "\n"; } | |
nested_fn(); | |
} | |
public function fn2() | |
{ | |
nested_fn(); | |
} | |
} | |
$nested = new NestedFunctions(); | |
$nested->fn2(); | |
$nested->fn1(); | |
// output: http://3v4l.org/hrNsX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class NestedFunctions | |
{ | |
public function fn1() | |
{ | |
function nested_fn() { echo 'yay' . "\n"; } | |
nested_fn(); | |
} | |
} | |
$nested = new NestedFunctions(); | |
$nested->fn1(); | |
$nested->fn1(); | |
// output: http://3v4l.org/buK93 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class NestedFunctions | |
{ | |
public function fn1() | |
{ | |
function nested_fn() { echo 'yay' . "\n"; } | |
nested_fn(); | |
} | |
public function fn2() | |
{ | |
function nested_fn() { echo 'yay' . "\n"; } | |
nested_fn(); | |
} | |
} | |
$nested = new NestedFunctions(); | |
$nested->fn1(); | |
$nested->fn2(); | |
// output: http://3v4l.org/WABfQ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class NestedFunctions | |
{ | |
public function fn1() | |
{ | |
function nested_fn() { echo 'yay' . "\n"; } | |
nested_fn(); | |
} | |
public function fn2() | |
{ | |
nested_fn(); | |
} | |
} | |
$nested = new NestedFunctions(); | |
$nested->fn1(); | |
$nested->fn2(); | |
// output: http://3v4l.org/2V57M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class NestedFunctions | |
{ | |
public function fn1() | |
{ | |
function nested_fn() { echo 'yay' . "\n"; } | |
nested_fn(); | |
} | |
} | |
$nested = new NestedFunctions(); | |
$nested->fn1(); | |
// output: http://3v4l.org/5brpq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment