Aug
5
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
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.
3 Comments to “PHP5-CLI versus Python CLI”
Leave a comment
Tags
Apple
Business
Critique
css
dell
Design
Design Patterns
facebook
firefox
Gmail
google
Hotmail
Interface
javascript
laptop
Links
Linux
Mac
Microsoft
netbook
OpenGL
OS
Philosophy
PHP
Podcast
Programming
Pyglet
Python
Pythonic Programming
Review
Search
services
Symfony
Time Management
Tutorial
Tutorials
Twitter
ubiquity
Ubuntu
update
Version Control
web design
Windows
Windows 7
Windows Mobile


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.