ID:               49274
 Updated by:       paj...@php.net
 Reported By:      cel...@php.net
 Status:           Analyzed
 Bug Type:         Feature/Change Request
 Operating System: *
 PHP Version:      5.3SVN-2009-08-16 (SVN)
 New Comment:

http://pastie.org/586442 should do it. I did not not test more than the
test case here.


Previous Comments:
------------------------------------------------------------------------

[2009-08-17 13:55:58] paj...@php.net

it is indeed valid for all objects but it is still an edge case.

A check for IS_OBJECT + tostring() existence could be easy enough and
with almost no impact(perf impact is null on the existing application).
If you have some time to write one, go ahead.

------------------------------------------------------------------------

[2009-08-17 13:52:56] cel...@php.net

the stdClass was just to illustrate the point, this happens with any
object that doesn't have a __toString().  I would imagine it would be
easier to check for IS_OBJECT and then see if it implements __toString
than to do a custom error handler.  The performance should be about the
same (dismal).

------------------------------------------------------------------------

[2009-08-17 13:48:45] paj...@php.net

As StdClass has no __toString implementation (obviously), it can't be
converted to string.

I tend to agree that it should not raise a fatal (recovable error) here
as it defeats the main purpose of this API.

I'm however not sure it is worth the effort to add custom error handler
for this edge case. Patch welcome, it could help to get this edge case
solved (I can't work on this exact issue any time soon).

------------------------------------------------------------------------

[2009-08-17 13:27:50] cel...@php.net

<?php
var_dump(filter_var(null, FILTER_VALIDATE_INT));
var_dump(filter_var(array(), FILTER_VALIDATE_INT));
var_dump(filter_var('hi', FILTER_VALIDATE_INT));
var_dump(filter_var(1.1, FILTER_VALIDATE_INT));
var_dump(filter_var(fopen('somefile', 'r'), FILTER_VALIDATE_INT));
var_dump(filter_var(1, FILTER_VALIDATE_INT));
var_dump(filter_var('1.0', FILTER_VALIDATE_INT));
?>

all work without error.

<?php
class blah {function __toString(){return '1';}}
var_dump(filter_var(new blah, FILTER_VALIDATE_INT));
?>

works without error.

Only filter_var with an object that doesn't implement __toString fails
with an error.  Either filter is incorrectly returning false with no
error on all of those other random types, or you're wrong, Jani.

------------------------------------------------------------------------

[2009-08-17 13:13:43] j...@php.net

This is not a bug. It's exactly what's supposed to happen. When you
pass crap in you get crap out. The language isn't supposed to hold your
hand in every corner.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/49274

-- 
Edit this bug report at http://bugs.php.net/?id=49274&edit=1

Reply via email to