From:             sala...@php.net
Operating system: OS X 10.5
PHP version:      5.3.0
PHP Bug Type:     SPL related
Bug description:  SplFileObject::fscanf pass-by-reference values

Description:
------------
SplFileObject::fscanf should behave identically to fscanf but that does
not appear to be the case. When attempting to provide variables into which
values should be assigned, the script either warns of undefined variables
(when passing apparently by value?) or throws out call-time
pass-by-reference E_DEPRECATED errors (when forcing pass-by-reference).

Reproduce code:
---------------
// fruits.txt
apple,100
banana,21

Pass by value:
<?php
$file = new SplFileObject("fruits.txt");
while (!$file->eof()) {
        var_dump($file->fscanf("%[a-z],%d", $fruit, $quantity), $fruit,
$quantity);
}
?>

Pass by reference:
<?php
$file = new SplFileObject("fruits.txt");
while (!$file->eof()) {
        var_dump($file->fscanf("%[a-z],%d", &$fruit, &$quantity), $fruit,
$quantity);
}
?>

Expected result:
----------------
Pass by value (the method definition should take variables by reference):

int(2)
string(5) "apple"
int(100)
int(2)
string(6) "banana"
int(21)

Pass by reference:

Should report E_DEPRECATED call-time pass-by reference. Which it does.

Actual result:
--------------
Pass by value:

<br />
<b>Notice</b>:  Undefined variable: fruit in <b>fruits.php</b> on line
<b>4</b><br />
<br />
<b>Notice</b>:  Undefined variable: quantity in <b>fruits.php</b> on line
<b>4</b><br />
<br />
<b>Notice</b>:  Undefined variable: fruit in <b>fruits.php</b> on line
<b>4</b><br />
<br />
<b>Notice</b>:  Undefined variable: quantity in <b>fruits.php</b> on line
<b>4</b><br />
int(2)
NULL
NULL
<br />
<b>Notice</b>:  Undefined variable: fruit in <b>fruits.php</b> on line
<b>4</b><br />
<br />
<b>Notice</b>:  Undefined variable: quantity in <b>fruits.php</b> on line
<b>4</b><br />
<br />
<b>Notice</b>:  Undefined variable: fruit in <b>fruits.php</b> on line
<b>4</b><br />
<br />
<b>Notice</b>:  Undefined variable: quantity in <b>fruits.php</b> on line
<b>4</b><br />
int(2)
NULL
NULL




Pass by reference:
<br />
<b>Deprecated</b>:  Call-time pass-by-reference has been deprecated in
<b>fruits.php</b> on line <b>4</b><br />
<br />
<b>Deprecated</b>:  Call-time pass-by-reference has been deprecated in
<b>fruits.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent
by (output started at fruits.php:4) in <b>fruits.php</b> on line
<b>1</b><br />
int(2)
string(5) "apple"
int(100)
int(2)
string(6) "banana"
int(21)



-- 
Edit bug report at http://bugs.php.net/?id=49032&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49032&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49032&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49032&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49032&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49032&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49032&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49032&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49032&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49032&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49032&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49032&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49032&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49032&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49032&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49032&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49032&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49032&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49032&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49032&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49032&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49032&r=mysqlcfg

Reply via email to