Last active
December 26, 2015 02:49
-
-
Save nurtext/7080962 to your computer and use it in GitHub Desktop.
Shorthand return values without variable assignment
This file contains hidden or 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 | |
// Example class | |
class Hello | |
{ | |
// Just a simple function wich returns a string | |
public function World($name = 'World') | |
{ | |
return sprintf("Hello %s\n", $name); | |
} | |
} | |
// Common example using an assignment | |
$hello = new Hello(); | |
echo $hello->World(); | |
// Shorthand return value without assignment | |
echo (new Hello)->World(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment