ZF 0.8.0 Unit Tests behaving different on PHP 5.2.1 and PHP 5.2.2-dev

php.internals

Sebastian Nohn

19 years ago
On PHP 5.2.1, ZendFramework 0.8.0 Unit Tests pass, while they fail on PHP 5.2.2-dev (latest CVS) on the same machine: 1) testDate(Zend_Date_DateObjectTest) Failed asserting that <string:6900000000> is identical to <string:6.9E+9> .../tests/Zend/Date/DateObjectTest.php:408 This behaviour is also reproducable on Zend Framework trunk. I don't know, where the bug is (ZF or PHP), so it would be nice, if PHP and ZF developers could come together to solve this. - Sebastian

Antony Dovgal

19 years ago
On 04/14/2007 08:50 PM, Sebastian Nohn wrote:
> On PHP 5.2.1, ZendFramework 0.8.0 Unit Tests pass, while they fail on > PHP 5.2.2-dev (latest CVS) on the same machine: > > 1) testDate(Zend_Date_DateObjectTest) > Failed asserting that <string:6900000000> is identical to <string:6.9E+9> > .../tests/Zend/Date/DateObjectTest.php:408
Would be nice to have a short but complete reproduce case. Referring to some test (which I personally have never seen) is not really helpful.
> This behaviour is also reproducable on Zend Framework trunk. > > I don't know, where the bug is (ZF or PHP), so it would be nice, if PHP > and ZF developers could come together to solve this. > > - Sebastian >
-- Wbr, Antony Dovgal

Sebastian Nohn

19 years ago
On Sat, April 14, 2007 8:29 pm, Antony Dovgal wrote:
> On 04/14/2007 08:50 PM, Sebastian Nohn wrote: >> On PHP 5.2.1, ZendFramework 0.8.0 Unit Tests pass, while they fail on >> PHP 5.2.2-dev (latest CVS) on the same machine: >> >> 1) testDate(Zend_Date_DateObjectTest) >> Failed asserting that <string:6900000000> is identical to >> <string:6.9E+9> >> .../tests/Zend/Date/DateObjectTest.php:408 > > Would be nice to have a short but complete reproduce case. > Referring to some test (which I personally have never seen) is not really > helpful.
This was the idea why PHP and ZF developers should come together. However, I investigated the issue and here is a small testcase: <?php $a = 6900000000; var_dump($a); $b = "A is: ".$a; var_dump($b); ?> 5.2.1 output is: float(6.9E+9) string(16) "A is: 6900000000" 5.2.2-dev output is: float(6.9E+9) string(12) "A is: 6.9E+9" - Sebastian

Antony Dovgal

19 years ago
On 04/15/2007 11:05 AM, Sebastian Nohn wrote:
> <?php > $a = 6900000000; > var_dump($a); > $b = "A is: ".$a; > var_dump($b); > ?> > > 5.2.1 output is: > > float(6.9E+9) > string(16) "A is: 6900000000" > > 5.2.2-dev output is: > > float(6.9E+9) > string(12) "A is: 6.9E+9"
Nice catch, thanks. What do you think is the most correct output for 1 000 000 000 000 000 (with precision = 14)? Versions <= 5.2.1 output "1E+15", 5.2.2 says "1.0E+15". Both options looks ok to me, but we need to decide which one is the best. I can find pros/cons for both options myself and it doesn't matter for me which one is chosen, though somebody might. I remember asking people on the channel and the most popular answer was "both are legal and look ok". Opinions?
-- Wbr, Antony Dovgal

Tijnema !

19 years ago
On 4/16/07, Antony Dovgal <antony@zend.com> wrote:
> On 04/15/2007 11:05 AM, Sebastian Nohn wrote: > > <?php > > $a = 6900000000; > > var_dump($a); > > $b = "A is: ".$a; > > var_dump($b); > > ?> > > > > 5.2.1 output is: > > > > float(6.9E+9) > > string(16) "A is: 6900000000" > > > > 5.2.2-dev output is: > > > > float(6.9E+9) > > string(12) "A is: 6.9E+9" > > Nice catch, thanks. > > What do you think is the most correct output for 1 000 000 000 000 000 (with precision = 14)? > Versions <= 5.2.1 output "1E+15", 5.2.2 says "1.0E+15". > > Both options looks ok to me, but we need to decide which one is the best. > I can find pros/cons for both options myself and it doesn't matter for me which one is chosen, though somebody might. > I remember asking people on the channel and the most popular answer was "both are legal and look ok". > > Opinions? > > -- > Wbr, > Antony Dovgal
The second one "1.0E+15" is more precise, as it has the extra 0. Other than that there's no big difference between them. But because it was in 5.2.1 and before, it might be better to choose the first one. Tijnema

Sebastian Nohn

19 years ago
On Mon, April 16, 2007 10:10 am, Antony Dovgal wrote:
> On 04/15/2007 11:05 AM, Sebastian Nohn wrote: >> <?php >> $a = 6900000000; >> var_dump($a); >> $b = "A is: ".$a; >> var_dump($b); >> ?> >> >> 5.2.1 output is: >> >> float(6.9E+9) >> string(16) "A is: 6900000000" >> >> 5.2.2-dev output is: >> >> float(6.9E+9) >> string(12) "A is: 6.9E+9" > > Nice catch, thanks. > > What do you think is the most correct output for 1 000 000 000 000 000 > (with precision = 14)? > Versions <= 5.2.1 output "1E+15", 5.2.2 says "1.0E+15".
Whatever is done, if the result is a different behaviour between 5.2.1 and 5.2.2, it needs to be documented in the change log / release notes. - Sebastian

Thomas Weidner

19 years ago
Sebastian, it should also be mentioned that when you are refferring to a test within ZF you should always look against the latest version of ZF. Since 0.8 I've fixed several issues for the I18N core and about 2000 lines of code have changed only for I18N which you are referring with Zend_Date_Dateobject-Tests. Independent on why this failure is there I also have to mention that I think that we will not fix issues within ZF which are raised due to the development tree of a php version. If php 5.2.2 is released and we have an issue with it we will fix it, but as this php version will probably be changed until it's release it would be nonsense to fix bugs which may be not in there when the new version of php is released. But keep your good work going... you've already found some nasty bugs which have been fixed ;-) Greetings Thomas I18N Team Leader for the Zend Framework ----- Original Message ----- From: "Sebastian Nohn" <sebastian@nohn.net> To: "Antony Dovgal" <antony@zend.com> Cc: "Sebastian Nohn" <sebastian@nohn.net>; "Zend Framework General" <fw-general@lists.zend.com>; <ilia@php.net>; <php-qa@lists.php.net>; <internals@lists.php.net> Sent: Monday, April 16, 2007 10:32 AM Subject: [fw-general] Re: [PHP-DEV] ZF 0.8.0 Unit Tests behaving different on PHP 5.2.1 and PHP 5.2.2-dev

Sebastian Nohn

19 years ago
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Thomas,
> it should also be mentioned that when you are refferring to a test > within ZF you should always look > against the latest version of ZF.
As already mentioned: This also happens in ZF trunk. ZF unit tests fail on any platform since sometime between 0.8.0 and 0.9.0 (see mine and others unresolved bug reports), so everything > 0.8.0 is no reference to test PHP (which I did).
> Independent on why this failure is there I also have to mention that I > think that we will not fix issues within ZF which are raised due to the > development tree of a php version. If php 5.2.2 is released and we have > an issue with it we will fix it, but as this php version will probably > be changed until it's release it would be nonsense to fix bugs which may > be not in there when the new version of php is released.
At that time I didn't know if the bug is a PHP bug or a ZF bug and I didn't want to investigate. Unfortunately neither PHP nor ZF developers wanted to investigate this, so I did it in the end. Best regards, Sebastian Nohn - -- Sebastian Nohn · Wolfstraße 29 · 53111 Bonn · Germany +49-170-4718105 · http://nohn.net/ · sebastian@nohn.net http://pgpkeys.pca.dfn.de:11371/pks/lookup?op=get&fingerprint=on&search=0xD47D55E0 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (MingW32) iD8DBQFGI8ebsvwfldR9VeARAqp3AJ9SvZ6wTGfn4B5tMwpdTDmWbOu5QgCgv4/6 uafKqBUpOtnjv1O0FZcFt38= =6wBP -----END PGP SIGNATURE-----

Dmitry Stogov

19 years ago
It is bad practice to use echo $float or var_dump($float) because they depends on php.ini settings. You should use printf() of number_format() for deterministic result. The float formatting algorithms were changed because of licensing issues and new ones are not 100% compatible with previous ones. Thanks. Dmitry.

Lukas Kahwe Smith

19 years ago
Dmitry Stogov wrote:
> It is bad practice to use echo $float or var_dump($float) > because they depends on php.ini settings. > You should use printf() of number_format() for deterministic result. > > The float formatting algorithms were changed because of > licensing issues and new ones are not 100% compatible with > previous ones.
Was this documented in the upgrading guide? regards, Lukas

Marcus Börger

19 years ago
Hello Lukas, float numbers are never perfect values. So should in anyway never rely on a certain output format. So there is nothing to document here. best regards marcus Tuesday, April 17, 2007, 10:16:39 AM, you wrote:
> Dmitry Stogov wrote: >> It is bad practice to use echo $float or var_dump($float) >> because they depends on php.ini settings. >> You should use printf() of number_format() for deterministic result. >> >> The float formatting algorithms were changed because of >> licensing issues and new ones are not 100% compatible with >> previous ones.
> Was this documented in the upgrading guide?
> regards, > Lukas
Best regards, Marcus

Sebastian Nohn

19 years ago
Marcus Boerger wrote:
> float numbers are never perfect values. So should in anyway never rely > on a certain output format. So there is nothing to document here.
We have a changed behavior here that should be documented. Otherwise users will run into problems. As the non-academic example that raised this discussion shows. - Sebastian

Sebastian Nohn

19 years ago
On Tue, April 17, 2007 9:55 am, Dmitry Stogov wrote:
> The float formatting algorithms were changed because of > licensing issues and new ones are not 100% compatible with > previous ones.
Could you please provide more details on that? - Sebastian

Sebastian Nohn

19 years ago
Dmitry Stogov wrote:
> It is bad practice to use echo $float or var_dump($float) > because they depends on php.ini settings. > You should use printf() of number_format() for deterministic result.
<?php $a = 6900000000; $b = $a.""; printf("%d", $a); echo "\n"; printf("%d", $b); echo "\n"; ?> PHP 5.2.1: -1689934592 2147483647 PHP 5.2.2: -1689934592 6 - Sebastian

Antony Dovgal

19 years ago
On 04/17/2007 10:16 PM, Sebastian Nohn wrote:
> Dmitry Stogov wrote: > >> It is bad practice to use echo $float or var_dump($float) >> because they depends on php.ini settings. >> You should use printf() of number_format() for deterministic result.
<?php $a = 6900000000; $b = $a.""; <-------------- that's the very same mistake printf("%d", $a); echo "\n"; printf("%d", $b); echo "\n"; ?> You're converting float to string and THEN trying to output as integer. My patch returns the old behaviour, though you're code is still wrong.
> PHP 5.2.2: > > -1689934592 > 6
#php -r 'printf("%d", 6900000000);' -1689934592 #php -r 'printf("%d", "6900000000");' 2147483647 #php -v PHP 5.2.2RC1 (cli) (built: Apr 16 2007 10:01:11)
-- Wbr, Antony Dovgal

Sebastian Nohn

19 years ago
Antony Dovgal wrote:
> On 04/17/2007 10:16 PM, Sebastian Nohn wrote: >> Dmitry Stogov wrote: >> >>> It is bad practice to use echo $float or var_dump($float) >>> because they depends on php.ini settings. >>> You should use printf() of number_format() for deterministic result. > > <?php > $a = 6900000000; > $b = $a.""; <-------------- that's the very same mistake > printf("%d", $a); echo "\n"; > printf("%d", $b); echo "\n"; > ?> > > You're converting float to string and THEN trying to output as integer. > My patch returns the old behaviour, though you're code is still wrong. > >> PHP 5.2.2: >> >> -1689934592 >> 6 > > #php -r 'printf("%d", 6900000000);' > -1689934592 > > #php -r 'printf("%d", "6900000000");' > 2147483647 > > #php -v > PHP 5.2.2RC1 (cli) (built: Apr 16 2007 10:01:11)
$ ./php -v PHP 5.2.2RC2-dev (cli) (built: Apr 17 2007 20:12:31) $ cat ~/test.php <?php $a = 6900000000; $b = "6900000000"; $c = $a.""; $d = (string)$a; printf("%d", $a); echo "\n"; printf("%d", $b); echo "\n"; printf("%d", $c); echo "\n"; printf("%d", $d); echo "\n"; ?> sh-3.1$ ./php ~/test.php -1689934592 2147483647 6 6 Best regards, Sebastian Nohn
-- Sebastian Nohn · Wolfstraße 29 · 53111 Bonn · Germany +49-170-4718105 · http://nohn.net/ · sebastian@nohn.net http://pgpkeys.pca.dfn.de:11371/pks/lookup?op=get&fingerprint=on&search=0xD47D55E0

Stanislav Malyshev

19 years ago
> <?php > $a = 6900000000; > $b = $a.""; > printf("%d", $a); echo "\n"; > printf("%d", $b); echo "\n"; > ?> > > PHP 5.2.1: > > -1689934592 > 2147483647 > > PHP 5.2.2: > > -1689934592 > 6
Huh, that's a strange thing. Why it happens?
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/

Dmitry Stogov

19 years ago
Tricky code - tricky result. Do you think php-5.1 result is perfect? :) BTW the difference is in implementation of %G format specifier. It seems, now it tries to produce the shortest string representation of float (I cannot remember why), but this is not conformed to POSIX specification Linux man: g,G The double argument is converted in style f or e (or F or E for G conversions). The precision specifies the number of signifi- cant digits. If the precision is missing, 6 digits are given; if the precision is zero, it is treated as 1. Style e is used if the exponent from its conversion is less than -4 or greater than or equal to the precision. Trailing zeros are removed from the fractional part of the result; a decimal point appears only if it is followed by at least one digit. Probably it should be fixed. Thanks. Dmitry.

Antony Dovgal

19 years ago
On 04/15/2007 11:05 AM, Sebastian Nohn wrote:
> <?php > $a = 6900000000; > var_dump($a); > $b = "A is: ".$a; > var_dump($b); > ?> > > 5.2.1 output is: > > float(6.9E+9) > string(16) "A is: 6900000000" > > 5.2.2-dev output is: > > float(6.9E+9) > string(12) "A is: 6.9E+9"
Fix committed, please test the next snapshot.
-- Wbr, Antony Dovgal

Sebastian Nohn

19 years ago
Hi, On Thu, April 19, 2007 11:33 am, Antony Dovgal wrote:
> On 04/15/2007 11:05 AM, Sebastian Nohn wrote: >> <?php >> $a = 6900000000; >> var_dump($a); >> $b = "A is: ".$a; >> var_dump($b); >> ?> >> >> 5.2.1 output is: >> >> float(6.9E+9) >> string(16) "A is: 6900000000" >> >> 5.2.2-dev output is: >> >> float(6.9E+9) >> string(12) "A is: 6.9E+9" > > Fix committed, please test the next snapshot.
Works! Thanks a lot! - Sebastian

Antony Dovgal

19 years ago
On 04/19/2007 03:27 PM, Sebastian Nohn wrote:
> Hi, >>> <?php >>> $a = 6900000000; >>> var_dump($a); >>> $b = "A is: ".$a; >>> var_dump($b); >>> ?> >>> >>> 5.2.1 output is: >>> >>> float(6.9E+9) >>> string(16) "A is: 6900000000" >>> >>> 5.2.2-dev output is: >>> >>> float(6.9E+9) >>> string(12) "A is: 6.9E+9" >> >> Fix committed, please test the next snapshot. > > Works! Thanks a lot!
Thanks you for letting us know =)
-- Wbr, Antony Dovgal