As noted in most comments, the first method (returning an array) is cleaner and more understandable, so itβs βbetterβ by this metric.
Depending on your use case, it might even be better not to try to return multiple values ββat all. Consider:
public function getDimensions() { return array( 'width' => $this->_width, 'height' => $this->_height ); } $dim = $canvas->getDimensions(); echo $dim['width'], ' x ', $dim['height'];
Compared with:
public function getWidth() { return $this->_width; } public function getHeight() { return $this->_height; } echo $canvas->getWidth(), ' x ', $canvas->getHeight();
This is a contrived example, obviously, but imagine that your methods do something expensive, not frivolous. Now imagine that you only need the first set of values, but since your method computes all of them for each call, you should wastefully compute everything and discard what you don't need.
source share