PHP返回不适用于Ubuntu [关闭]

We ran into a mind boggling issue today.. Code is written in PHP 5.6 on Phalcon framework. My colleague can't run my code because when I write return from a controller action method (meant for Ajax request) he gets a whole view instead of the json object I try to return. However, when we use die() or exit() (which doesn't return to the caller as return does but in the action method it doesn't matter) everything gets returned as intended. Also I am running Debian 8.8, he's running Ubuntu. Both of us are using NetBeans 8.2

When you call die() or exit(), everything is stopped.

From PHP manual :

(PHP 4, PHP 5, PHP 7)
exit — Output a message and terminate the current script

This includes the framework. It sounds like you might have did something like echo out the json and expect it to output only the json. I have not used Phalcon but many frameworks have their own series of functions and scripts to go through before a page is rendered. Therefore by calling return, the framework's script was put to work, to construct a full view and outputting to the browser, your JSON might have been buried somewhere inside.

On the other hand, by calling exit(), everything stops right there and no more rendering functions from the framework will run.

Learn your framework and adapt, hope that helps.