|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73839 suggestion to improve clarity of functions to use for queue / stack behavior
Submitted: 2016-12-29 21:26 UTC Modified: -
From: pjvleeuwen at gmail dot com Assigned:
Status: Open Package: Arrays related
PHP Version: 7.1.0 OS: n/a
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-12-29 21:26 UTC] pjvleeuwen at gmail dot com
For background see:

Currently as a new(ish) PHP developer the documentation left some unclarity for me on how to use stacks and queues.

The documentation on the array_push(), array_pop(), array_shift() and array_unshift() functions could more clearly describe there typical usage when dealing with queues and stacks.

Based on performance I would expect that the advisable usage would be: for stacks use push & pop ; for queues use push & shift.
Please let me know if this is an incorrect usage. My suggestions below are based on those assumptions. Either way the documentation could be improved by giving some more clarity, so if my assumptions were incorrect, then please still take the suggestions below and modify where appropriate.

I would propose to dedicate one sentence on this for each function in the description and update the examples accordingly.

In the description of array_push()
change: "array_push() treats array as a stack"
to: "array_push() treats array as a stack (along with array_pop()) or queue (along with array_shift())"

In the description of array_pop()
add: "Use array_pop() along with array_push() to treat the array as stack."

In the description of array_shift()
add: "Use array_shift() along with array_push() to treat the array as queue."

In the description of array_unshift()
add: "Note: to treat the array as typical queue or stack, consider using other methods, see array_push() for pointers."

In the example of array_shift()
change the variable name from "$stack" to "$queue".

In the example of array_unshift()
change the variable name from "$queue" to "$array".

Possibly also update the descriptions in the 'see also' section accordingly for added clarity.


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Apr 21 23:01:23 2021 UTC