php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36098 CachingIterator::__tostring do not work
Submitted: 2006-01-20 11:05 UTC Modified: 2006-01-23 03:25 UTC
From: quick_defect at yahoo dot com Assigned: helly (profile)
Status: Closed Package: SPL related
PHP Version: 5.1.2 OS: *
Private report: No CVE-ID: None
 [2006-01-20 11:05 UTC] quick_defect at yahoo dot com
Description:
------------
First,I want to know how to use __tostring.But there is not doc. So I tried with -3: 
and what I get:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Flags must contain only one of CIT_CALL_TOSTRING, CIT_TOSTRING_USE_KEY, CIT_TOSTRING_USE_CURRENT' in CachingIterator::__tostring.php:12
Stack trace:
#0 CachingIterator::__tostring.php(12): CachingIterator->__construct(Object(ArrayIterator), -3)
#1 {main}
  thrown in CachingIterator::__tostring.php on line 12

So I know I should use CIT_CALL_TOSTRING, CIT_TOSTRING_USE_KEY or CIT_TOSTRING_USE_CURRENT.
then I tried:
$ak=(new CachingIterator($asx,CIT_TOSTRING_USE_KEY ));

But I again got an exception which prompted that the argument was still invalid.


Reproduce code:
---------------
<?php
error_reporting(E_ALL);
$asp=array("one"=>1,"two"=>2,"three"=>3,"four"=>4,"five"=>5,"six"=>6);
$kfc=array("trap");

$jsp=(new ArrayObject($asp));
$mcd=(new ArrayObject($kfc));

$asx=$jsp->getIterator();
$coca=$mcd->getIterator();

$ak=(new CachingIterator($asx,CIT_TOSTRING_USE_KEY ));
?>




Expected result:
----------------
no exception throwed out

Actual result:
--------------
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'CachingIterator::__construct() expects parameter 2 to be long, string given' in CachingIterator::__tostring.php:12
Stack trace:
#0 CachingIterator::__tostring.php(12): CachingIterator->__construct(Object(ArrayIterator), 'CIT_TOSTRING_US...')
#1 {main}
  thrown in CachingIterator::__tostring.php on line 12

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-20 11:31 UTC] sniper@php.net
Please read the error message. 
 [2006-01-23 02:40 UTC] quick_defect at yahoo dot com
sniper,I know you are very busy. But PLS read my description carefuly.

First, error message told me that:
'Flags must contain only one of CIT_CALL_TOSTRING, CIT_TOSTRING_USE_KEY,
CIT_TOSTRING_USE_CURRENT' 
then I use:
new CachingIterator($asx,CIT_TOSTRING_USE_KEY );
this time,the error message told me:
'CachingIterator::__construct() expects parameter 2 to be long, string
given' 

What hell does it mean then? PHP told me use CIT_TOSTRING_USE_KEY as the second argument, and I did so.Then PHP told me 'CachingIterator::__construct() expects parameter 2 to be long'

Don't you think there is a contrflict in your error message?
 [2006-01-23 03:25 UTC] helly@php.net
The error message showed the old const names and you didn't check your notices.

marcus@zaphod /usr/src/PHP_5_1 $ php --rc CachingIterator
make: `sapi/cli/php' is up to date.
Class [ <internal:SPL> <iterateable> class CachingIterator implements Iterator, Traversable, OuterIterator ] {

  - Constants [4] {
    Constant [ integer CALL_TOSTRING ] { }
    Constant [ integer CATCH_GET_CHILD ] { }
    Constant [ integer TOSTRING_USE_KEY ] { }
    Constant [ integer TOSTRING_USE_CURRENT ] { }
  }
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC