php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67183 Caret (power of) in for results in infinite loop
Submitted: 2014-05-02 20:17 UTC Modified: 2014-05-03 09:59 UTC
From: ianbytchek at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.12 OS: OSX
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ianbytchek at gmail dot com
New email:
PHP Version: OS:

 

 [2014-05-02 20:17 UTC] ianbytchek at gmail dot com
Description:
------------
This doesn't work.

for ($i = 0; $i < 2 ^ 10; $i++) {
    echo $i;
}

This does.

for ($i = 0; $i < (2 ^ 10); $i++) {
    echo $i;
}

Is it actually a bug or is that how op precedence is expected to work here?

Test script:
---------------
for ($i = 0; $i < 2 ^ 10; $i++) {
    echo $i;
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-02 20:23 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-05-03 01:13 UTC] anon at anon dot anon
Caret isn't "power of", it's xor. `2^10` is 8, not 1024. If you want 1024, use `1<<10` or `pow(2, 10)`.
 [2014-05-03 09:59 UTC] ianbytchek at gmail dot com
Awkwaaaaard :) thanks for pointing out.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 19:00:01 2026 UTC