Last active
August 11, 2020 15:00
-
-
Save dariooddenino/5103c250b33ea0995c136c9e3145934c to your computer and use it in GitHub Desktop.
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 Functions { | |
public static function getScope() { | |
// Here I had to instantiate the class twice, or the static method would not be callable (???) | |
return ['Functions\Inner' => new \Functions\Inner((new \Function\Inner([]))::getScope()) ]; | |
} | |
public function __construct($scope) { | |
if ($scope !== []) { | |
$this->scope = $scope; | |
$this->foo = self::fun(1)(2); | |
$this->bar = ($scope['Functions__Inner'])->fun3(5); | |
} | |
} | |
public function fun2($v) { | |
return function ($b) use ($v) { | |
return ($this->scope['Functions\Inner'])->fun3($b); | |
} | |
} | |
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
module Functions where | |
import Functions.Inner (fun3) | |
fun2 :: Int -> Int -> Int | |
fun2 _ b = b | |
foo :: Int | |
foo = fun2 1 2 | |
bar :: Int | |
bar = fun3 5 |
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 | |
namespace Functions; | |
class Inner { | |
// Added a getScope static method | |
public static function getScope() { | |
return ['Some\Other' => 3]; | |
} | |
// The constructor sets the scope | |
public function __construct($scope) { | |
if ($scope !== []) { | |
$this->scope = $scope; | |
$this->foreignVal = $scope['Some\Other']; | |
} | |
} | |
// This from static to non-static | |
public function fun3 ($arg) { | |
return $arg + $this->foreignVal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment