php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47903 "@" operator does not work with string offsets (PHP_5_2 only!)
Submitted: 2009-04-05 19:05 UTC Modified: 2009-04-06 23:57 UTC
From: cFreed at orange dot fr Assigned: felipe
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.9 OS: *
Private report: No CVE-ID:
 [2009-04-05 19:05 UTC] cFreed at orange dot fr
Description:
------------
A case where the error-control operator @ does NOT work, despite of what the manual says.

Reproduce code:
---------------
---
From manual page: language.operators.errorcontrol
---
The manual says:
"A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it."

This is not always true.

As shown by the example given, this works, assuming $cache IS AN ARRAY:
<?php
$value = @$cache[$key]; 
// will not issue a notice if the index $key doesn't exist.
?>

But it does not work if $cache IS A STRING, and $key is an integer higher than strlen($cache)-1. in other words:
<?php
$str='abc';
$value=@$str[5];
// will issue the notice "Uninitialized string offset 5 in...".
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-06 08:34 UTC] kalle@php.net
Verified in the PHP_5_2 branch only, PHP_5_3 and HEAD does not produce this, reclassified
 [2009-04-06 11:40 UTC] jani@php.net
Felipe, this same (?) issue was reported in bug #39018 and was supposed to be closed too..was the fix omitted from PHP_5_2 branch?

 [2009-04-06 11:59 UTC] felipe@php.net
Yes, these fix was just committed in 5.3+.
 [2009-04-06 23:57 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Mon Apr 21 00:02:04 2014 UTC