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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 19 16:01:27 2024 UTC