while (true)
與while (\true)
和最重要的任何人都可以澄清爲什麼boolean
受名稱空間影響PHP
?'while(true)`vs`while( true)`有什麼區別?
24
A
回答
55
在PHP true
,false
和null
是常量,它們在名稱空間中被保護不被覆蓋。因此下面的無效代碼:
namespace Foo;
const true = false; // Cannot redeclare constant 'true'
但仍可以覆蓋這樣一個常數使用「」定義()「」:
namespace Foo;
define('Foo\true', false);
var_dump(true); // bool(false)
然而,這是不支持的功能(可能被稱爲bug),PHP可以自由地假定true
不能被覆蓋。
// Note: This uses eval() to make sure the define() runs before the constexpr
// constant resolution happens
namespace Foo;
define('Foo\true', false);
var_dump(eval('namespace Foo;
static $t = true;
return $t;')); // bool(true)
爲什麼替代發生在constexpr情況下,而不是在「正常」情況的原因是在實現中的錯誤:在一個constexpr上下文的true
例如使用將不受上述定義的影響。對於constexprs,替換髮生在名稱解析之前,而對於正常的代碼,它發生在名稱解析之後。
正確的實現方式是始終在名稱解析後替換,但在替換過程中特別考慮了true
,false
和null
。我打算修復這個PHP 7的問題。
相關問題
- 1. while(true)vs socket.accept()
- 2. 什麼是「while true do skip」
- 3. while(true)vs wait + condition同步
- 4. while(true)或tcp listen:什麼更有效?
- 5. (;;){}或while(true){}有什麼更好?
- 6. while(true)和for(;;)之間的實際區別是什麼?
- 7. Loop while true
- 8. while(true)loop lagg
- 9. system.formatexception while(true)loop
- 10. while(true)條件的意義是什麼?
- 11. 使用「while(true){...}」是什麼意思?
- 12. while(* p){p ++;},while(* ++ p){;}和while(* p ++){;}之間有什麼區別?
- 13. while(true)loop without break
- 14. do while(true)while sys.o.print(「Hi」);而(假);
- 15. 「-Dmaven.test.skip.exec」和「-Dmaven.test.skip = true」有什麼區別?
- 16. FileStream.Flush()和FileStream.Flush(True)有什麼區別?
- 17. 有什麼區別:while和:在clojure時?
- 18. 這個while循環有什麼區別?
- 19. while(++ i < - j)&while(i ++ <j--)有什麼區別?
- 20. js while(true){} blocks event loop
- 21. 正在退出Python While True
- 22. Shell break while-true循環
- 23. while true try catch嵌套
- 24. Python Threading:Multiple While True循環
- 25. while(True)loop break SSH script
- 26. 使用什麼:sql == true vs sql === true?
- 27. true是什麼區別?和布爾值
- 28. while(cin)和while(cin >> num)之間的區別是什麼
- 29. SomeValue之間的區別{get;} = true; vs SomeValue => true;在屬性
- 30. Turbo C++:while(fin)vs while(!fin.eof())
https://github.com/igorw/retry/issues/3 - *「這看起來好一點,但是在頂部有一個效率相當低的FETCH_CONSTANT指令。這需要對igorw \ true進行命名空間查找,我們可以通過用while(true)替換while(true)來優化它。 這會擺脫FETCH_CONSTANT調用,並將布爾值設爲內聯:「* – 2014-09-24 18:23:29
' TRUE/FALSE'的行爲與其他常量一樣http://php.net/manual/en/reserved.constants.php – 2014-09-24 18:25:48
自5.3.0版本開始,所有的函數/類/變量/常量/ etc都在PHP中被命名空間,而真/ false/null/etc是常量,就像您可能自己定義的任何常量一樣......大多數屬於全局名稱空間,但PHP將首先檢查當前名稱空間,然後檢查全局名稱空間沒有在當前命名空間中找到它們,所以使用該前綴可以防止當前名稱空間檢查的開銷 – 2014-09-24 18:30:26