27 questions
-1 votes
1 answer
4k views
Fatal error: Uncaught Error: Call to undefined function create_function() while activating wordpress plugin
I got an error while activating a plugin in my WordPress website Fatal error: Uncaught Error: Call to undefined function create_function() in /home4/seosexey/gifting.icowebtech.com/wp-content/plugins/...
-1 votes
2 answers
1k views
Laravel collection map use private function in same class instead closure
I use the map function to loop each object of collections. The closure method is too long and I tried to make it a private function. But I cannot successfully call the function. Here is my sample code....
1 vote
1 answer
137 views
PHP automatic binding of $this, is it a copy or an extend?
When using an anonymous PHP function that is defined inside a class context, the docs say "the current class is automatically bound to it, making $this available inside of the function's scope". But ...
0 votes
2 answers
265 views
PHP closure return multiple functions
I'm trying to achieve almost similar things/properties of closure in PHP which is available in JS. For example function createGreeter($who) { return function(){ function hello() use ($...
0 votes
1 answer
43 views
PHP: access a variable from a class/method, both defined inside the same closure
The following code is working as expected: $b = 42; var_dump("b: " . $b); class A { function foo() { global $b; var_dump("b: " . $b); } } $instance = new A(); $instance-&...
-1 votes
2 answers
80 views
Php Dynamic class methods
I have an array (class property) which stores PHP methods (i.e., of class 'Closure'). Just like this. $this->methods[$name]=$action; $action is the function. When I try invoking the function ...
1 vote
1 answer
48 views
Value of $total not being set inside lumen collection map function
I have a lumen collection object for my order and use map function to iterate over it and do some logic. I also need the total value of the order which is calculated using quantity * price. But the ...
0 votes
2 answers
46 views
Php require() does not recognize aliased class
So mainly this is caused by my code structure: File1.php use \Class1 as Blah; require 'File2.php'; File2.php $closure = function ($arg) { return new Blah($arg); }; Somehow the part behind ... ...
1 vote
2 answers
3k views
Laravel Commands, Pthreads and Closure
There is a need to perform a specific process multiple threads. I learned about the extension for php - pthreads. For example, a simple script outside Laravel works fine and I liked the results. I ...
0 votes
1 answer
58 views
Pass Eloquent Model As An Closure Argument In PHP
I'm using Laravel Illuminate/Database outside of laravel application. I'm trying to pass the Eloquent model as my closure argument but its throwing an error. May be I'm passing it wrongly. My code is ...
2 votes
2 answers
5k views
Laravel eloquent foreach loop
I am having a foreach loop that goes through an array, and saves data with eloquent. And it works fine when it is like this: foreach($questions['questions'] as $question) { $questionObject = ...
1 vote
1 answer
380 views
Unexpected behaviour in PHP Altorouter when passing parameters
Setup I'm accessing this url: <host>/render/z63034/RBLR/GLZB. My url pattern is as such: /render/[a:title]/[a:bpFrom]/[a:bpTo]. My route gets added like so: $router->map("GET", "/render/[...
4 votes
1 answer
2k views
Is there a way to update caller scope variables from php closure [duplicate]
use keyword with php closure is a pretty clear way to extend the scope of handpicked variable to closure. Is there any way if we need to update the value of some variable in caller function scope ...
7 votes
2 answers
3k views
How to inspect a closure in php?
I have a function that is being passed a Closure. I want to find out the name of the method that closure is derived from. When I call print_r, it outputs this: Closure Object ( [static] => Array ...
1 vote
1 answer
650 views
How do you compare classes that contain `Closure`?
So, how do you compare classes that contain Closure ? It looks like you can't. class a { protected $whatever; function __construct() { $this->whatever = function() {}; } } ...