Aug
5

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.

  • Digg
  • del.icio.us
  • Facebook
  • Google Buzz
  • Google Reader
  • Reddit
  • NewsVine
  • RSS
  • Twitter
  • Technorati
  • StumbleUpon

3 Comments to “PHP5-CLI versus Python CLI”

  • I had to throw a wrench into the works. PHP does more than imply that $test2 is 0…

    Try running this:

    #!/usr/bin/php

    Turns out PHP is just passing on its ignorance in the error. =]

  • Bah, the comments messed up the script I pasted in. I’ll send it to you.

  • Yeah man, or extend the post if you want.

Leave a comment