# jochem@xxxxxxxxxxxxx / 2007-01-03 16:43:14 +0100: > Roman Neuhauser wrote: > > # jochem@xxxxxxxxxxxxx / 2007-01-03 14:07:31 +0100: > >> Roman - you make some very good point but the pragmatist in me > >> says of your first example - why the F*** would anyone pass in an object and > >> blindly push it through printf() ?? that sucks as far as code goes (personally > >> evening being so diligent as to implement __toString() on the relevant class is > >> asking for bad news - too much magic imho) > >> > >> if the function should be capable of taking an object or a string it should > >> check what it recieves. > >> > >> the way I see it this is bad code by design - and needs to be fixed. > > > > Well, why the F*** would anyone use a language that allows you to pass > > incompatible objects to a function and crashes when you do so? ;) > > > > Errors and warnings are fine for languages where the compilation step is > > separate from the run. For a language like PHP, anything but > > "RuntimeException" means your perfectly correct code can crash at > > runtime, without you having a slightest chance to react (in the code). > > you have to pay some kind of price for dynamic typing and intepreted > running. You don't, look at Python. Instead of warnings and fatal errors, good for logging purposes at best, you get to choose how to handle the problem. What kind of dynamic typing are we talking about if f($any) { printf("%s", $any); } is bad code? If you dare to use dynamic features in PHP you're begging to have your throat cut by some call to undefined method, or hop in to lala land with an "undefined member variable access" warning... If problems with the "dynamic typing" of PHP end in somewhat undynamic fatal errors, your only choice is to have all paths in the program statically verified, IOW, steer completely clear of the dynamic features. That'll be a terribly tedious job. You can do this in Python (completely safe and meaningful): def f(any): print "%s" % any You can even call any method on any object safely: def g(o): o.f() If o doesn't have a callable member called "f", you'll get an exception you can catch: def g(o): try: o.f() except AttributeError: print >> stderr, "oops!" The lack of global error handlers allows mixing of independently developed software, that's quite dynamic. If you believe that something like f($any) { if (is_string($any)) { printf("%s", $any); } else if (...) { ... } } is better than the single sprintf() version, we'll just have to agree to disagree. Where's the dynamism again? You could write this in C++: void f(any a) { cout << a; } with less typing more dynamism than you get with PHP. And the resulting binary won't crash at runtime. -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php