php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #82 type conversion string to number
Submitted: 1998-02-19 04:20 UTC Modified: 1998-02-19 09:12 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: Brian dot Craigie at necs dot demon dot co dot uk Assigned:
Status: Closed Package: Other
PHP Version: 3.0 Latest CVS OS: Solaris 2.5
Private report: No CVE-ID: None
 [1998-02-19 04:20 UTC] Brian dot Craigie at necs dot demon dot co dot uk
I'm using PHP3 cvs version as of 17th feb.  This isn't really a bug IMO, but it's odd.

Using the code:-

<?
$Y2="6";
$Y1="5";
$MINYVALUE=0;
$SCALE=4;

echo "Y2=$Y2,Y1=$Y1,MINYVALUE=$MINYVALUE,SCALE=$SCALE<P>\n";

$dbg=($Y2+$Y1-$MINYVALUE)*$SCALE;

echo "dbg=$dbg<P>\n";
?>

---
result:-

Y2=6,Y1=5,MINYVALUE=0,SCALE=4

dbg=260


---

Yet (6+5-0)*4 = 44

Now, I know the code is wrong because I'm assigning string values to $Y1 and $Y2, but why does it not convert the values correctly?

I've now fixed my code by removing the quotes from around the numbers, and the calculation is then correct.

I suppose I don't want a bug fix so much as to know why an implicit string to number conversion didn't work.

Thanks!

Brian

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-02-19 09:12 UTC] zeev
The plus operator is overloaded for strings
 [2020-05-07 13:12 UTC] nikic@php.net
Automatic comment from SVN on behalf of nikic
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=349753
Log: Remove useless declare statement from example

Patch by SjonHortensius.

Closes php/doc-en#82.
 [2021-09-03 09:50 UTC] git@php.net
Automatic comment on behalf of sy-records
Revision: https://github.com/php/doc-zh/commit/b10d46e7c397de2059a55dadd8f15ba4e7ed3f5e
Log: Fix typo
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Nov 30 00:03:14 2021 UTC