Tag: php

  • 一才难求

    有志开发网店的好手、生手请留言。工作地杭州。

  • Learned something basic

    今天又长知识了。

    首先,最简单的,更正了长久以来的想当然,php 下 explode(‘,’, ”) != array(),而是得到长度为 1 的数组,key 是数值 0,value 是空字符串。天哪,我有多少个程序是基于 explode(‘,’, ”) == array() 写下去的,这下影响大了,得好好查一查。

    其次,发现一个不晓得是 sshfs 的 bug 还是 gedit 的 bug。复制错误的过程是:用 Nautilus 或 Dolphin 打开 sshfs 挂载的目录,右击创建一个新文件。文件创建是成功的,属性是 774,用 gedit 打开它却无法保存,提示是没有写权限;但用 kwrite 编辑保存一切正常;用 gedit 再编辑 kwrite 编辑过的文件又能保存。或者,在右击创建一个新文件后,执行一次 chmod 774 filename,也能用 gedit 编辑保存了。

    再次,发现在 IE6 下,用 javascript 增大元素的尺寸(比如 jQuery widget 化,增加 border,增加 padding,等),会增大父元素的尺寸。哪怕父元素已用 css 静态赋以宽度值,宽度也会被改变,这是某些精心布局在标准浏览器下很好看,到了 IE6 就面目全非的一大原因。万恶的 IE6 啊,当然从另一方面,说明精心布局仍不够“精心”。为 IE6 布局好比极限运动,挑战好心情的极限;如果看到下属多花一倍时间 fix for IE6,挑战的也是老板的心理极限。

    然后,发现 jQuery gallery 里有两个 themes (Humanity, Vader) 的参数不太正常,多了 tr 参数,不知道怎么多出来的,删了似乎没影响。

    最后,如果父元素包含所有的子元素都是 float:left 或 float right 的话,不做特殊操作,父元素是没有高度的。父元素的后续元素用一个 clear:both 就能站到该站的位置,但如要为父元素本身画一个边框就稍有难度。最早我用的办法是在这个元素所有的子元素之后增加一个隐形的<div style=”height:0; clear:both;”></div>,但这个硬生生加进去的元素改变了 DOM 结构,破坏了语义,不够 SEO。在 Magento 里学到了另一个方法 :after { clear:both; },如 .clearer 的示例,但要为低版本的 IE 专门写 clear after fix。我维护一份自己的 style.css,override Magento 原版的 style.css。我觉得这个任务就很“繁重”,如果再来一份自己的 style-ie.css,override Magento 原版的 style-ie.css,就为 clear after fix?总觉得小题大作。今天发现一个 clear after all floating children 的 neat solution,就是在父元素上设定 style=”overflow:auto; zoom:1″。overflow 让父元素调整到应有的高度,zoom 也是必须的,否则 IE6…,唉!

    最后的最后,发现 z-index 值在 IE6 下被重置的简单通用的 fix。这个问题的来源是若干个 position 后的元素,给它们设定 z-index,IE6 下根本不按设定值 layout,而且还摸不到规律。比如下拉菜单,有时被其他东西给压住。fix 是赋予下拉菜单 z-index 时,赋予父元素(整个菜单)更高的 z-index。

  • Constants are not overridden as varibles

    今天发现我写的一个底层的 Magento class 竟然有个低级错误。错误的根源是我在父类里定义了一个常量

    const XML_PATH_TO_SYSTEM_CONFIG = 'some value';
    

    然后在父类里有个方法用到了这个常量

    public static function getConfigValue()
    {
    	return Mage::getStoreConfig(self::XML_PATH_TO_SYSTEM_CONFIG);
    }
    

    然后在子类里复写了常量

    const XML_PATH_TO_SYSTEM_CONFIG = 'some other value';
    

    但子类并没有父类的方法 getConfigValue()。我指望通过复写每个子类的常量后调用子类的方法 getConfigValue() 得到不同的值,哪知道每次都得到跟父类的方法 getConfigValue() 相同的值。

    仔细一想,这是因为父类的 self::XML_PATH_TO_SYSTEM_CONFIG 并没有被复写。改用一个变量来存储值就能达到我的原定目的,但这个变量不能是静态变量,否则效果还是跟常量一样。

  • Lack of EAV framework for php

    最近我在仔细研究 Magento EAV 的机理。

    Magento 的强大跟 EAV module 的强大有很大关系,花点时间去研究很值得。我还发现 Magento EAV module 中一些不足之处,但我无力改进。于是想借鉴一下其他的 EAV framework 是怎么实现的,悲惨的是,如果说到 EAV php implementation,似乎 Magento EAV 就是唯一一个成熟的开源方案。但 EAV java implementation 倒有一些独立的选择。

    这是不是暗示 php 先天不足?尽管 Magento 让 php 在电子商务领域出尽风头,但这很可能是 php 的极致了。

  • I am leaving Zend Server

    Creating domain error after installing Zend Server
    Creating domain error after installing Zend Server

    I used to deem Zend Server is overall a good solution for php website development and deployment. However, over a year’s time I realise it brings so many troubles. It is not compatible with Plesk as shown in the screenshot. I can not solve this problem.

    It stops yum on Fedora. I can solve this problem but, troublesome.

    Do I enjoy any unique feature of Zend Server? None as I can remember. Occasionally I use “debug on server”, but it is a feature of Zend Debug, not of Zend Server.

    Also, Zend Server pulls me back to Apache, to which I prefer Nginx.

    Actually, I have no reasons to love Zend Server. So I decide to leave it.

  • yum install php-5.3-curl-zend-server

    我快被 zend server 搞疯了。不过说到底是我自己不好——新装了一台 Fedora 14,添了 zend.repo 以后忘了运行

    yum install zend-server-ce-php-5.3
    

    过了几天开始用它来调试 Magento。貌似 zend server php 替换了原有的 fedora php,因为 php.ini 是来自 /usr/local/zend/etc。这给我很大程度上一个误导,以为 zend server 已经装好了。

    结果 Magento 跑不起来,第一个错误是没有 pdo,我略有纳闷,zend server 怎么不代我完成 pdo 安装?不过没细想,用

    yum install php-pdo-mysql
    

    解决问题。(不过回想起来,也没搞清楚这到底装了哪个版本的 pdo)

    随后发现进不了后台,第二个错误是没有 curl,这下折腾了两个小时,用

    yum install php-curl
    

    说已安装(fedora 把 php-curl 包含在 php-common)。然后我用

    yum reinstall php-curl
    

    当然无济于事。试遍各种可能的命令都不成功,两小时后发觉 zend server 没装过,于是一装 zend server,顺利启动 Magento。

    最后说一下,如果非要单独装 zend server 版的 php curl,可以用

    yum install php-5.3-curl-zend-server
    
  • Non working day calculation is included in msdk module

    Although I am not ready to release msdk module for Magento, I finish a model called Qian_Msdk_Model_Nwd. It is to judge if a given date is a non working day by some pre-defined and user-defined rules. It can also work out what date of next n’th working day is.

    There are two types of rules, rule by date or rule by week. For Non Working Day (NWD) fixed by date, there is normally a make-up following working day as NWD if the original one is Saturday or Sunday. For NWD fixed by week, there is no make-up, usually.

    For the rule simplicity, I always assume make-up. When you are writing your own rules and do not want make-up to some rules, add “=” modifier to the beginning of each of them.

    How to read and write NWD rules?

    First thing to remember, as a general checking rule, I go through each line separated by “\n”, and verify if the supplied date (if omitted, assume today’s date) fall into the line of rule. There is no connection between lines, so do not expect a rule can make up another one.

    Second thing to remember, as PHP allows a date like “2010/13/33”, I allow you write rules like that too. However, avoid it if you can.

    Third thing to remember, PHP regards Sunday as 0 Saturday as 6, and I do the same.

    Fourth thing to remember, when ISO number weeks, it regards week starts Monday, and I do the same. If you do not know what I am talking about, read ISO-8601.

    Fifth thing to remember, I do not have a good algorithm to work out dates by lunar calendar. So that is no smart way to write a rule for Easter. Ditto many Chinese holidays. You have to use fixed date every year. I hope it won’t cost you long time write down all fixed dates of 10 years lunar NWD and just sit while this programme runs for 10 years. After 10 years, aha, you’ll find your way.

    OK, let’s get on to rule writing.

    1. Rule by date is something like “yyyy/mm/dd”, or “yyyy/mm/dd,dd,dd”. yyyy, mm or dd can take asterisk “*” as wild-card.

    For new year day, it is “*/01/01”. This is simplest scenario. For Christmas and Boxing day, it is “*/12/25,26”. Be careful here, do not write two rules “*/12/25” and “*/12/26”. They can not achieve the same result as “*/12/25,26”, because a rule can make up a following working day if the rule date is Saturday or Sunday, but it can not exclude days by other rules.

    You have to write in one rule if two or more NWDs are connected. However, the dates are not necessarily continuous. In theory, you can write a rule like “*/12/24,26”. In reality, I did not see any NWDs are scheduled like this.

    2. Rule by week is something like “yyyy/mm/dd/weekNumber/weekDay”, or “yyyy///weekNumber/weekDay”. yyyy, mm or dd can take asterisk “*” as wild-card. “yyyy///weekNumber/weekDay” use ISO-8601 to find the week and weekDay. I will cover it in section 3.

    “yyyy/mm/dd/weekNumber/weekDay” uses a reference year/month/day to find the n’th weekDay. N is specified by weekNumber.

    2.1 If both mm and dd are “*”, it uses a reference year. For example, “*/*/*/10/1” means 10th Monday of any year.

    2.2 If mm is a number, but dd is “*”, it uses a reference month. For example, “*/05/*/1/1” means 1st Monday in May. A lot of England bank holidays are specified this way.

    2.3 If dd is a number, it uses a reference day. For example, “*/06/06/0/1” means the Monday of the week where June 6 sits.

    In case of 2.1 and 2.2, weekNumber can take a negative number which means the last n’th weekDay. For example, “*/05/*/-1/1” means the last Monday in May. WeekNumber zero does not make sense here.

    In case of 2.3, weekNumber can take zero (means the same week), a positive number (n’th week forward), or a negative number (n’th week backward).

    3. “yyyy///weekNumber/weekDay” ISO-8601 style looks similar to case 2.1. But they are totally different.

    For example, “2011///1/6” means Saturday of week 1 of year 2011, which is 2011/01/08. But “2011/*/*/1/6” means the 1st Saturday of year 2011, which is 2011/01/01.

    Another example, “2010///52/6” means Saturday of week 52 of year 2010, which is 2011/01/01 (Yes, it goes into the following year). But “2010/*/*/52/6” means the 52th Saturday of year 2010, which is 2010/12/25.

    I think writing documentation helps programming. I have revised NWD documentation for 3 times or more, and every time I found a new way to structure the model.

    I also think any date calculation look simple but actual coding is very complex. This model took me half a year to finish although I am full time on it.

  • public static or static public

    在 php 中,public static 或 static public 怎么写都可以,所以我一直不知道哪种是正统的写法(象我这样追求正统的人,或许 python 更适合我?)。

    今天费点时间看看别人是怎么看待 public static or static public 这个问题的。我的结论是 public static 是正统的写法,于是我想把以前随意写成的 static public 都更新成 public static。所幸的是,以前一直用的都是 public static。倒是在 magento 的源码里找到一堆 static public,或许 magento developers 没被要求一定要怎么写,所以源码里混合了 public static 和 static public。

    我觉得 inconsistency 是最糟糕的,或许我在这个问题上吹毛求疵了。

  • phpMyAdmin 2002 error

    最近把家里的测试服务器 Zend Server php 5.2 卸载了,重新安装了 5.3。phpMyAdmin 随着 5.2 卸载也被卸载了。我用

    yum install phpMyAdmin

    重新安装了 phpMyAdmin。在 config.inc.php 设置了必要的参数,但 phpMyAdmin prompted:

    #2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)

    phpMyAdmin 2002 error
    phpMyAdmin 2002 error

    我浪费了很多时间检查了所有可能的错误,却解决不了问题。最后在 phpmyadmin.net 下载了源码,使用同样的 config.inc.php,顺利登录!

  • Install Zend Server with Plesk

    据说 Zend 正在跟 Plesk 探讨怎么让他们的产品相互兼容。

    我没那么高深,无法让 Zend Server 完全兼容 Plesk,但可以做到——

    前台用上 Zend Server 版的 php (Plesk 前后台使用两个安装的 php),尽管 Plesk 后台误认为 php module not installed。我强行修改了 psa 数据库里的数据,改了什么我不记得了。说实话,把 Zend Server 和 Plesk 跑在一起意义也不大。

    Parallels Installed Components
    Parallels Installed Components
    Parallels with php 5.3.2 from Zend Server
    Parallels with php 5.3.2 from Zend Server
    Parallels php not installed
    Parallels php installed but showing as not installed