Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float Rule bug #38

Closed
EduardoLopes opened this issue Oct 8, 2011 · 3 comments
Closed

Float Rule bug #38

EduardoLopes opened this issue Oct 8, 2011 · 3 comments

Comments

@EduardoLopes
Copy link

A regra float retorna true independente se o numero é de ponto flutuante ou não:

<?php
use Respect\Validation\Validator as v;

        var_dump(v::float()->validate(1.234)); //bool(true)
        var_dump(v::float()->validate(23)); //bool(true)

Fiz alguns teste com a função filter_var() e só retornou false quando testei com uma string:

<?php
var_dump(filter_var('some string' , FILTER_VALIDATE_FLOAT)); //bool(false)
var_dump(filter_var(10 , FILTER_VALIDATE_FLOAT)); //float(10)

Não seria melhor usar is_float()? Modifiquei aqui e funcionou.

@ramon-to
Copy link

ramon-to commented Oct 8, 2011

ponto flutuante = números reais
http://www.php.net/manual/en/language.types.float.php

@EduardoLopes
Copy link
Author

Nossa, eu sabia que tinha alguma coisa errada, não podia ser problema do filter_var(). O pior é que eu olhei essa pagina varias vezes. Desculpe o erro.

@alganet
Copy link
Member

alganet commented Oct 9, 2011

Esse bug me fez rever o código e ver que havia um erro que os testes não cobriam. O número 0 (zero) é um float válido, e o validador não passava ele corretamente. A solução encontrada foi usar uma combinação de is_float com filter_var!

Não foi exatamente o que você reportou, mas o fato desse bug ter sido aberto ajudou bastante!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants