Tag Archives: Errors

PHP5-CLI versus Python CLI

I just thought this was kind of interesting.   Out of the box CLI comparison of PHP and Python type errors :D

Python

>>> test = 123
>>> test2 = "ewfwef"
>>> test / test2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'int' and 'str'

PHP

$test = 123;
$test2 = "werwe";
echo $test/$test2;

Warning: Division by zero in Command line code on line 1

It’s nice that python tells you what is really wrong here, you can’t divide an integer by a string! PHP on the other hand implies that $test2 is equivalent to 0.
It should be noted that python is doing a trace and PHP is not. Doing a trace on the error in PHP would give more information but since PHP is very weak with types, you would probably have to notice the error on your own.