批评一下 PHP

March 23, 2008 10:43 pm GMT-0700 | In Tech

PHP 里函数多如牛毛,加进去又没什么统一规划,搞得现在成了命名法大杂烩,比如:

  • obj_verb 型的:array_slice() http_inflate()
  • verb_obj 型的:create_function() parse_str()
  • verbobj 不加下划线:setcookie() addslashes()
  • 直接把 POSIX 传统函数拿来用的:opendir() fopen()
  • 这种算什么呢:error_reporting() htmlspecialchars() 特别是这个 htmlspecialchars 命名毫无章法
  • 新老 DOM 类函数不一样:一个叫 getAttribute(),另一个叫 get_attribute()
  • 你可能会说,那同类函数可能命名法就一致了吧?也不全是,日历函数:
    • verb_obj:cal_days_in_month()
    • 大写首字母不加下划线:JDDayOfWeek()
    • 突然又全小写了:jdtounix()

(其实 PHP 函数名不分大小写,最后这俩只是文档故意添乱) 晕死。有人说,你真弱,用多了就全熟了。好吧,我是比较弱,可是我知道有人在知名大公司天天写 PHP 还是和我一样晕……PHP 函数命名为什么这么乱?给俩链接:

换个话题,最近 PHP 的 substr 函数被人改坏了。

There was a small inconsistency between PHP 5.2.1 and 5.2.2. In PHP 5.2.1, substr($str, $start) returns the full $str if ($start < 0 && abs($start) > strlen($str)). But starting from PHP 5.2.2, FALSE would be returned. Before 5.2.2, this behavior was conveniently used to extract at most N last characters of a string, e.g. $str = substr($str, 30); limits $str to at most 30 characters and truncate from the beginning if necessary. However, this no longer works! See also: diff-5.2.1-5.2.2, bug 41375. This is likely to change back in PHP 5.3, given what’s recently been done on PHP_5_3 branch.

PHP Doc 有正方呼吁:This is a small inconsistency, one of those things that makes the life of a PHP programmer like hell. Bugzilla 上反方辩护:The fact that it worked up until 5.2.1 doesn’t mean that you should have used it. 这个问题其实最开始只是因为别的原因无意间改错的,但是 PHP 内部却有人坚持错误,有人报告这个问题也被归类为 Bogus(意思就是说,RTFM,回家好好读文档去)。其实文档也不明确,现在基于各种原因,PHP 5.3 分支上又改回去了,真是搬起石头砸自己的脚。

说个微软搬石头砸自己脚的故事。IE 最开始搞出 {client,offset,scroll}{Top,Width,Height,Left} 十二个很有意义的 HTML 属性用来方便的设置/获取对象大小/位置等信息,实在是一个很好很强大的发明,基本也铁定进 HTML5 了。不过 IE 里面的制造标准不明确,各类元素定义略有不同,反倒别的浏览器抄得更和谐。搞到现在的局面是,微软自己发明的东西,反倒被 QuirksMode 说成 IE 里 incorrect/buggy,不如别的浏览器“正确”,真是衰啊。

Tags: , , , ,

3 Comments »

RSS feed for comments on this post.

  1. wahaha m$

    nb acore

    Comment by zyw — March 23, 2008 11:54 pm GMT-0700 #

  2. Google用php吗?你干私活了吧

    Comment by hammer — March 24, 2008 6:35 am GMT-0700 #

  3. django && opera ROCKS!

    Comment by hutuworm — March 24, 2008 8:30 pm GMT-0700 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This weblog is licensed under a Creative Commons License.
Powered by WordPress. Theme based on Pool by Borja Fernandez.