Why can't i call a function before defining it in a try block in php

前端 未结 1 1559
无人及你
无人及你 2020-12-22 12:24

When I call a function inside try block before defining. it gives me fatal error

What I was trying to do is this

try {
   echo someFunction();
   fu         


        
相关标签:
1条回答
  • 2020-12-22 12:55

    When a function is defined in a conditional manner it's definition must be processed prior to being called. Just switch the echo and function like below.

    try {
        function someFunction()
        {
            return 'hello';
        }
        echo someFunction();
    } catch (Exception $e ){
        return $e->getMessage();
    }
    

    http://php.net/manual/en/functions.user-defined.php

    0 讨论(0)
提交回复
热议问题