2012-07-29 77 views
1

當我們在全球範圍的PHP中使用return時,在return之後,執行就停止了嗎? 或處理將繼續?在PHP代碼中返回

<?php 

if(defined("A")) return; 
define("A", true); 

echo "Hello"; 

if(defined("A")) return; 
define("A", true); 

echo "Hello"; 
?> 
+3

執行會去on..you需要使用'exit'停止進一步執行.. – 2012-07-29 07:57:54

+1

具有讀取HTTP: //php.net/manual/en/function.return.php – Musa 2012-07-29 08:00:31

+2

@ Mr.Alien錯了。執行將被停止 – 2012-07-29 08:03:47

回答

4

如果要停止腳本,你最好使用exit,因爲回報率應該在功能只用於!

http://php.net/manual/en/function.return.php
http://php.net/manual/en/function.exit.php

在你的情況下,該腳本將結束由文檔說:return will also end the execution of an eval() statement or script file

+0

我不負責這downvote,但OP確實詢問有關'在全球返回範圍。不在功能。 – 2012-07-29 08:01:55

+0

是的,經過多次編輯,但在第一種情況下,它沒有被指出! – PoulsQ 2012-07-29 08:04:27

+0

是的。看看帖子的編輯。 – 2012-07-29 08:05:30

1

你的腳本會後第一return

停止,以此documenation說:

如果返回從主腳本文件中調用,那麼腳本 執行結束