php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73672 正则表达式运算顺序疑问
Submitted: 2016-12-07 06:37 UTC Modified: 2016-12-07 09:15 UTC
From: jay_medivh at foxmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.0.14RC1 OS: windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jay_medivh at foxmail dot com
New email:
PHP Version: OS:

 

 [2016-12-07 06:37 UTC] jay_medivh at foxmail dot com
Description:
------------
这里有一段程序中的代码

var_dump(18130300 == 18130300 ? "hello world" : 18130300 ? 1 : 2);

如上代码在Java和C#中运行结果为hello world , 但是在php中变成了后边的1,我有疑问,这是php特定的运算顺序的确与Java和C#不同还是其他原因

Test script:
---------------
<?php

var_dump(18130300 == 18130300 ? "hello world" : 18130300 ? 1 : 2);

Expected result:
----------------
hello world

Actual result:
--------------
1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-07 09:15 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2016-12-07 09:15 UTC] laruence@php.net
这是是历史遗留问题, 结合性不同, PHP的是左结合, 而Java是右结合.

可以参考: http://stackoverflow.com/questions/20559150/ternary-operator-left-associativity

thanks
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 03:01:28 2024 UTC