Reputation: 680
I'm not taking about programming in php but php itself. Is it possible that creators of php will make echo to dump for example arrays like the var_dump does?
Upvotes: 1
Views: 296
Reputation: 53940
in php you can create an object that walks like an array and quacks like an array, but still is an object with a customizable __toString method.
class ary implements ArrayAccess
{
function __construct() {
$this->a = func_get_args();
}
function offsetExists($k) {
return isset($this->a[$k]);
}
function offsetGet($k) {
return $this->a[$k];
}
function offsetSet($k, $v) {
$this->a[$k] = $v;
}
function offsetUnset($k) {
unset($this->a[$k]);
}
function __toString() {
return implode(', ', $this->a);
}
}
$a = new ary(11, 22, 33);
$a[1] = 66;
echo $a;
of course, it would be better is arrays already were normal objects like in other languages, but i don't think this is going to happen in the nearest future.
Upvotes: 2
Reputation: 449425
Is it possible that creators of php will make echo to dump for example arrays like the var_dump does?
I think you mean if echo
gets passed a variable that can not be displayed as a string, show a dump, instead of the current behaviour of showing its data type (e.g. Array
)?
That would indeed make sense, but also be dangerous: What if an object contains data that the end user is not supposed to see?
I doubt the echo
function (or, to be more exact, the string parsing functions of PHP) will undergo such a radical change, for exactly this reason.
Upvotes: 4
Reputation: 19225
Such a radical change to existing functionality would be a recipe for a lot of broken code. So I'd say no.
That said, this is PHP we're talking about, so it wouldnt surprise me....
Upvotes: 2