Re: [PHP-DEV] PHP 4.0 Bug #9794: array_keys resets the array pointer and can not be used when looping

2001-03-16 Thread Andrei Zmievski

On Fri, 16 Mar 2001, Stig Venaas wrote:
> It seems like this is a common problem, I think perhaps most of the
> PHP code (the C code) could be made cleaner if the Zend API separated
> pointers from the array structure. So that one could create a pointer
> and pass it as an argument to Zend hash functions, or something like
> that. It could be useful to have several pointers at once. One other
> option could be to have a pointer stack per hash, with two hash
> functions for pushing and popping the current pointer on/off the
> stack.

All this is already possible and has existed in Zend since exactly 1
year ago when I put it in... Extension authors can use *_ex versions of
hash functions and supply their own HashPosition parameter.

-Andrei

Documentation is worth it just to be able
to answer all your mail with 'RTFM'. -- Alan Cox

-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] PHP 4.0 Bug #9794: array_keys resets the array pointer and can not be used when looping

2001-03-16 Thread Stig Venaas

On Fri, Mar 16, 2001 at 11:21:39AM -0600, Andrei Zmievski wrote:
> On Fri, 16 Mar 2001, Daniel Beckham wrote:
> > Awesome.  Are you planning to just fix the array_keys function, or will
> > there be a change as to how the array functions work with the array
> > pointers?
> 
> It'll be on a case-by-case basis. Some functions do need to move the
> pointers.

It seems like this is a common problem, I think perhaps most of the
PHP code (the C code) could be made cleaner if the Zend API separated
pointers from the array structure. So that one could create a pointer
and pass it as an argument to Zend hash functions, or something like
that. It could be useful to have several pointers at once. One other
option could be to have a pointer stack per hash, with two hash
functions for pushing and popping the current pointer on/off the
stack.

A final option. It's easy for the C code using the Zend API to save the
hash key for the element that the pointer currently points to. If there
was a Zend function for setting the pointer (taking hash key as argument),
it would be easier for the PHP C code to save and restore the pointer.

Well, just some quick thoughts written down in a couple of minutes, there
might be better alternatives, but I think one should consider some general
ways of solving this problem.

Stig

-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] PHP 4.0 Bug #9794: array_keys resets the array pointer and can not be used when looping

2001-03-16 Thread Andrei Zmievski

On Fri, 16 Mar 2001, Daniel Beckham wrote:
> Awesome.  Are you planning to just fix the array_keys function, or will
> there be a change as to how the array functions work with the array
> pointers?

It'll be on a case-by-case basis. Some functions do need to move the
pointers.

-Andrei

It is commonly the case with technologies that you can get
the best insight about how they work by watching them fail.
-- Neal Stephenson

-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] PHP 4.0 Bug #9794: array_keys resets the array pointer and can not be used when looping

2001-03-16 Thread Daniel Beckham

Awesome.  Are you planning to just fix the array_keys function, or will
there be a change as to how the array functions work with the array
pointers?

Thanks,

Daniel Beckham

- Original Message -
From: "Andrei Zmievski" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Friday, March 16, 2001 11:18 AM
Subject: Re: [PHP-DEV] PHP 4.0 Bug #9794: array_keys resets the array
pointer and can not be used when looping


> I'll fix this problem soon. It's even in the TODO.
>
> On Fri, 16 Mar 2001, [EMAIL PROTECTED] wrote:
> > From: [EMAIL PROTECTED]
> > Operating system: linux 2.2.16
> > PHP version:  4.0.4pl1
> > PHP Bug Type: Scripting Engine problem
> > Bug description:  array_keys resets the array pointer and can not be
used when looping
> >
> > The following code is broken:
> >
> > $arr = array("a", "b", "c");
> > foreach ($arr as $a) {
> >   echo "$a\n";
> >   echo max(array_keys($arr));
> > }
> >
> > It stops after the first array element because array_keys resets the
array pointer. (Or at least it's moved to the end...)
> >
> > This is sort of a (repectful) complaint that I have about PHP and they
way it's been written.  Arrays are systematically prostituted by the array
functions because each one of them sees fit to reset the array pointer
instead of just working off of a copy, or at the very least, returning the
array pointer to it's previous state.
> >
> > Is there some reason that the array pointer can't be returned to it's
previous state after the array functions are finished with it?
> >
> >
> >
> > --
> > Edit Bug report at: http://bugs.php.net/?id=9794&edit=1
> >
> >
> >
> > --
> > PHP Development Mailing List <http://www.php.net/>
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
>
>
>
> -Andrei
> * If Bill Gates had a nickel for every time Windows crashed.. Oh, wait.. *
>
>


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] PHP 4.0 Bug #9794: array_keys resets the array pointer and can not be used when looping

2001-03-16 Thread Andrei Zmievski

I'll fix this problem soon. It's even in the TODO.

On Fri, 16 Mar 2001, [EMAIL PROTECTED] wrote:
> From: [EMAIL PROTECTED]
> Operating system: linux 2.2.16
> PHP version:  4.0.4pl1
> PHP Bug Type: Scripting Engine problem
> Bug description:  array_keys resets the array pointer and can not be used when 
>looping
> 
> The following code is broken:
> 
> $arr = array("a", "b", "c");
> foreach ($arr as $a) {
>   echo "$a\n";
>   echo max(array_keys($arr));
> }
> 
> It stops after the first array element because array_keys resets the array pointer. 
>(Or at least it's moved to the end...)
> 
> This is sort of a (repectful) complaint that I have about PHP and they way it's been 
>written.  Arrays are systematically prostituted by the array functions because each 
>one of them sees fit to reset the array pointer instead of just working off of a 
>copy, or at the very least, returning the array pointer to it's previous state.
> 
> Is there some reason that the array pointer can't be returned to it's previous state 
>after the array functions are finished with it?
> 
> 
> 
> -- 
> Edit Bug report at: http://bugs.php.net/?id=9794&edit=1
> 
> 
> 
> -- 
> PHP Development Mailing List 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 



-Andrei
* If Bill Gates had a nickel for every time Windows crashed.. Oh, wait.. *

-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] PHP 4.0 Bug #9794: array_keys resets the array pointer and can not be used when looping

2001-03-16 Thread danbeck

From: [EMAIL PROTECTED]
Operating system: linux 2.2.16
PHP version:  4.0.4pl1
PHP Bug Type: Scripting Engine problem
Bug description:  array_keys resets the array pointer and can not be used when looping

The following code is broken:

$arr = array("a", "b", "c");
foreach ($arr as $a) {
  echo "$a\n";
  echo max(array_keys($arr));
}

It stops after the first array element because array_keys resets the array pointer. 
(Or at least it's moved to the end...)

This is sort of a (repectful) complaint that I have about PHP and they way it's been 
written.  Arrays are systematically prostituted by the array functions because each 
one of them sees fit to reset the array pointer instead of just working off of a copy, 
or at the very least, returning the array pointer to it's previous state.

Is there some reason that the array pointer can't be returned to it's previous state 
after the array functions are finished with it?



-- 
Edit Bug report at: http://bugs.php.net/?id=9794&edit=1



-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]