PHP variable scope within Try/Catch block

后端 未结 3 1301
孤独总比滥情好
孤独总比滥情好 2021-02-07 09:06

In PHP, how do variable scope rules apply to Try/Catch blocks? Do variables declared within the try block go out of scope when the block has finished? Or are they i

3条回答
  •  再見小時候
    2021-02-07 10:03

    Your code is valid. Variable scope in PHP is by function, not block. So you can assign a variable inside the try block, and access it outside, so long as they're in the same function.

提交回复
热议问题