Bug #73054 [Opn->Ana]: default option ignored when object passed to int filter

From: Date: Fri, 09 Sep 2016 10:23:18 +0000
Subject: Bug #73054 [Opn->Ana]: default option ignored when object passed to int filter
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203905@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73054&edit=1

 ID:                 73054
 Updated by:         cmb@php.net
 Reported by:        dormilich at netscape dot net
 Summary:            default option ignored when object passed to int
                     filter
-Status:             Open
+Status:             Analyzed
 Type:               Bug
 Package:            Filter related
 Operating System:   Mac OS X 10.11.6
 PHP Version:        5.6.25
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

I can confirm both issues: <https://3v4l.org/mAtsv> and
<https://3v4l.org/qEUtH>.

The first issue has been introduced with the fix for bug #49274,
where the function bails out too early thereby ignoring any
default value.

The second issue is actually a duplicate of bug #67167, which has
been fixed (in this regard) only as of PHP 7. The fix should be
backported to PHP 5.6.


Previous Comments:
------------------------------------------------------------------------
[2016-09-09 08:46:28] dormilich at netscape dot net

Description:
------------
When any object is passed through filter_var() with the FILTER_VALIDATE_INT filter and a default
option the result is always boolean false instead of the default value. 

Second, the FILTER_NULL_ON_FAILURE flag also shows no effect on passed objects.

Test script:
---------------
<?php
$id = filter_var(new stdClass, FILTER_VALIDATE_INT, [
    'options' => ['default' => 2],
]);
var_dump($id);

Expected result:
----------------
int(2)

Actual result:
--------------
bool(false)


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



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


Thread (9 messages)

« previous php.bugs (#203905) next »