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().


  • Tv - The value of the last element.


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();


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

$v = Vector {};

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