by simon baird

Tuesday, August 25, 2009

another way that php sucks

~> cat test.php
<?php
$a = array('foo','bar');
print_r($a);

$a .= 'baz'; # php: "i guess you wanted to convert that to a string? no problem"
print_r($a); # oh joy...
~> php test.php
Array
(
    [0] => foo
    [1] => bar
)
Arraybaz~> # weep

~> cat test.rb

a = ['foo','bar']
puts a.inspect

a += 'baz' # dear php. notice how this is an error? sanity prevails. thank you ruby
puts a.inspect
~> ruby test.rb
["foo", "bar"]
test.rb:4:in `+': can't convert String into Array (TypeError)
    from test.rb:4

No comments: