Skip to content

Instantly share code, notes, and snippets.

@dariooddenino
Last active August 11, 2020 15:00
Show Gist options
  • Save dariooddenino/5103c250b33ea0995c136c9e3145934c to your computer and use it in GitHub Desktop.
Save dariooddenino/5103c250b33ea0995c136c9e3145934c to your computer and use it in GitHub Desktop.
<?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);
}
}
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
<?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