One anonymous method call in another method in php

Albertestein

I have a problem in calling an anonymous method in another anonymous method.

<?php
    $x = function($a)
    {
        return $a;
    };
    $y = function()
    {
        $b = $x("hello world a");
        echo $b;
    };
    $y(); 
?>

Error:

Notice: Undefined variable: x in C:\xampp\htdocs\tsta.php on line 7

Fatal error: Function name must be a string in C:\xampp\htdocs\tsta.php on line 7

arbogastes

Add use to your $y function, then scope of $y function will see $x variable:

$y = function() use ($x){
    $b = $x("hello world a");
    echo $b;
};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

One anonymous method call in another method in php

From Dev

Is there an anonymous call of a method in Python?

From Dev

Call one method from another one

From Dev

Find out if one method could call another

From Dev

Call a method from one controller inside another

From Dev

Method call from one class to another not working?

From Dev

Javascript call one object method after another

From Dev

How to call a Method from one class to another

From Dev

How to call parameters from one method to another?

From Dev

Javascript One after another method call

From Dev

Cannot call an Anonymous Class Method

From Dev

Java Method call in anonymous classes

From Dev

Cannot call an Anonymous Class Method

From Dev

Properly call anonymous method with async

From Dev

how to call a php extension method from another php extension method

From Dev

How to call one method from another method in javascript?

From Dev

Is is a good practice to call a method inside another method? - PHP

From Dev

Javascript call method in another method

From Dev

PHP OOP, why does one method call require the self keyword and another doesn't?

From Dev

Meteor.call() one method per time restriction, or async method call blocking another methods

From Dev

Meteor.call() one method per time restriction, or async method call blocking another methods

From Java

call method in one stateful widget from another stateful widget - Flutter

From Dev

is it possible to call one jax-rs method from another?

From Dev

How to call one method from another inside function

From Dev

ES6 call one method from another

From Dev

How do you call a method in one class, from another class?

From Dev

how to call method of one fragment from another fragment class in android

From Dev

ReactJS - Call One Component Method From Another Component

From Dev

How do I call one controllers method in another controller in Node

Related Related

  1. 1

    One anonymous method call in another method in php

  2. 2

    Is there an anonymous call of a method in Python?

  3. 3

    Call one method from another one

  4. 4

    Find out if one method could call another

  5. 5

    Call a method from one controller inside another

  6. 6

    Method call from one class to another not working?

  7. 7

    Javascript call one object method after another

  8. 8

    How to call a Method from one class to another

  9. 9

    How to call parameters from one method to another?

  10. 10

    Javascript One after another method call

  11. 11

    Cannot call an Anonymous Class Method

  12. 12

    Java Method call in anonymous classes

  13. 13

    Cannot call an Anonymous Class Method

  14. 14

    Properly call anonymous method with async

  15. 15

    how to call a php extension method from another php extension method

  16. 16

    How to call one method from another method in javascript?

  17. 17

    Is is a good practice to call a method inside another method? - PHP

  18. 18

    Javascript call method in another method

  19. 19

    PHP OOP, why does one method call require the self keyword and another doesn't?

  20. 20

    Meteor.call() one method per time restriction, or async method call blocking another methods

  21. 21

    Meteor.call() one method per time restriction, or async method call blocking another methods

  22. 22

    call method in one stateful widget from another stateful widget - Flutter

  23. 23

    is it possible to call one jax-rs method from another?

  24. 24

    How to call one method from another inside function

  25. 25

    ES6 call one method from another

  26. 26

    How do you call a method in one class, from another class?

  27. 27

    how to call method of one fragment from another fragment class in android

  28. 28

    ReactJS - Call One Component Method From Another Component

  29. 29

    How do I call one controllers method in another controller in Node

HotTag

Archive