Skip to main content

pop

Note

This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information.

Remove the last element of the current Vector and return it

public function pop(): Tv;

This function throws an exception if the current Vector is empty.

The current Vector will have n - 1 elements after this operation, where n is the number of elements in the current Vector prior to the call to pop().

Returns

  • Tv - The value of the last element.

Examples

This example shows that pop() returns the last element and removes it from the Vector:

$v = Vector {'red', 'green', 'blue', 'yellow'};

$last_color = $v->pop();

\var_dump($last_color);
\var_dump($v);

This example shows that trying to pop from an empty Vector will throw an exception:

$v = Vector {};

$last_element = $v->pop(); // Throws InvalidOperationException