php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16697 %= operator
Submitted: 2002-04-19 08:04 UTC Modified: 2002-04-19 16:00 UTC
From: spagnoli at dualservice dot it Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 4.0CVS-2002-04-19 OS: Linux
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: spagnoli at dualservice dot it
New email:
PHP Version: OS:

 

 [2002-04-19 08:04 UTC] spagnoli at dualservice dot it
I've tried a trick I often use in C++; the PHP syntax should be identical:

$a=0;
while ([condition]) {
  $mystring= ++$a%=8 ? "A" : "B";
  [...]
}

the value of $mystring should be "B" seven times and then "A" once, keeping the value of $a in the range [0..7].

If $a is useless for other purposes, the following gives the same result:

$a=0;
while ([condition]) {
  $mystring= ++$a%8 ? "A" : "B";
  [...]
}

whith two differences:
$a is no loger necessarily in the range [0..7] and, above all, tha latter works, but tha former doesn't!

I've tried to parse "++$a" writing
  $mystring= (++$a)%=8 ? "A" : "B";

but it doesn't work.

Since this problem is related to operators, I don't think you need information about my modules or my system, but if I'm wrong ask me for that.
Thank you.

Regards,

Davide Spagnoli

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-19 16:00 UTC] tal@php.net
Not a bug > bogus.
$a = ++$b = 1 is meaningless, you cannot assign values to ++$b or $b++.

-Tal
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 20:01:31 2024 UTC