GoLang pht\Queue::front

request it (239)
GoLang replacement for PHP's pht\Queue::front [edit | history]

Do you know a GoLang replacement for PHP's pht\Queue::front? Write it!

PHP pht\Queue::front

PHP original manual for pht\Queue::front [ show | php.net ]


(PECL pht >= 0.0.1)

pht\Queue::frontReturns the first value from a queue


public mixed pht\Queue::front ( void )

This method will remove a value from the front of the queue (in constant time). Attempting to return the front value from an empty queue will result in an Error exception.


Due to the fact that all values in a pht\Queue are serialised, extracting a value from the queue will require it to be deserialised. This can incur a noticeable performance hit if the inspection of the queue's front value is performed within a loop.


This function has no parameters.

Return Values

The value on the front of the queue.


Example #1 Retrieving the front value of a queue


use pht\Queue;

$queue = new Queue();



The above example will output:


Example #2 Retrieving the front value in a loop (bad example - don't do this)


use pht\Queue;

$queue = new Queue();


for (
$i 0$i count($queue->front()); ++$i); // quadratic runtime

Example #3 Retrieving the front value in a loop (good example)


use pht\Queue;

$queue = new Queue();


$front $queue->front(); // create a separate variable
for ($i 0$i count($front); ++$i); // linear runtime