________________________________
De: Igor Escobar <titiolin...@gmail.com>
Para: "<php-general@lists.php.net>" <php-general@lists.php.net>
Enviadas: Sexta-feira, 16 de Setembro de 2011 7:07
Assunto: [PHP] Bug?

Anyone can explain this?

https://gist.github.com/1220404

Part of the code are in portuguese so...
iguais = equal
diferentes = different

Regards,
Igor Escobar
*Software Engineer
*
+ http://blog.igorescobar.com
+ http://www.igorescobar.com
+ @igorescobar <http://www.twitter.com/igorescobar>


The person who posted this (andersonfraga) has set up four "string" comparison 
tests.

It was commented by augustohp who said:-


float_a.php
Existe uma configuração no php.ini da precisão de números de ponto flutuante. 
Acima desse número, todos são arredondados.

There is a configuration setting in php.ini that determines the precision of 
floating point numbers. A "number" greater than that setting causes rounding.

float_b.php
Com a bcmath você não está comparando tipos especializados 
de dados, mas sim dados binários. É mais demorado, mas é extremamente 
preciso, sempre.

With bcmath you are doing a binary comparison. It is slower but precise, always.

string_a.php
Quando você usa "==" você não compara os tipos, e não força o 
interpretador a respeitar o tipo de dado fornecido. O que acontece 
então!? O PHP converte o tipo para o tipo de dado mais apropriado em uma 
condição: boolean, inteiro, etc ...
Se você converter para inteiro, vai ver que os números são iguais.

When you use the "==" operator you don't compare data types and don't force the 
interpreter to respect the data type supplied. What happens then? PHP converts 
the type to the most appropriate data type and returns a boolean. (I assume he 
means "casting". I always thought that you had to cast the variables implicitly 
in order to use "==".)
I think he is saying in the next sentence that if you cast them to integers, 
"you'll see that the numbers are equal". Doesn't make any sense to me, but 
then, I'm no "expert".

string_b.php
Aqui sim você compara strings, garante que elas não sofram cast para outro tipo 
de dado. Você pode atingir isso usando "===" também, sem essa função de 
comparação de strings.

Here you compare strings, and guarantee that they don't suffer casting to 
another data type. You can achieve the same thing by using the "===" operator 
also, without (using) this string comparison function.


Hope this helps.

Cheers,
Robert

Reply via email to