You are currently browsing the archives for the php tag.

April 7, 2010

PHP成员函数中竟然也能用static声明变量 10:08 am

又发现一个PHP Feature,PHP成员函数中竟然也能用static声明变量。怎么想怎么奇怪,你都创建新实例了,怎么static还是有效?不过有时候还蛮有用的。

class static_var {
    function __construct($name) {
        $this->name = $name;
    }
    function output() {
        static $counter;
        $counter++;
        echo $counter.'|'.$this->name.'|';
    }
}
$t1 = new static_var('take 1');
$t1->output();
$t2 = new static_var('take 2');
$t2->output();
Filed under: Programming — Tags: Comments (1)

February 28, 2009

Mac OS X 上构建 PHP5 1:47 pm

在安装 PHP 前先安装 Mysql,Apache2 我用的是 Mac 内置的那个。下载 PHP 5.2.9 源码,然后执行:
./configure –prefix=/usr/local –with-iconv –with-gd
–with-xmlrpc –enable-zip –with-openssl=/usr –enable-ftp –enable-sockets
–enable-mbstring –enable-bcmath –with-curl –with-zlib-dir=/usr
–with-mysqli=/usr/local/mysql/bin/mysql_config
–with-mysql=/usr/local/mysql
–with-config-file-path=/etc/php.ini –with-apxs2=/usr/sbin/apxs
配置过程中会因为缺少某些开发包而出错,用 Mac port 安装一下就可以了

make && sudo make install

这样创建的 libphp5.so 是无法被 Apache 载入的,需要用 lipo 处理一下 Apache 的二进制程序

/usr/sbin$ sudo cp httpd httpd-fat
/usr/sbin$ sudo lipo httpd -thin i386 -output httpd

完了重启 Apache 就可以使用了:
sudo apachectl restart

Filed under: Programming,System — Tags: , Comments (0)

January 11, 2009

原来 Mac 自带了 PHP 6:30 pm

1. 启用 Apache,System Preferences -> Sharing -> Web Sharing
2. 编辑 /etc/apache2/httpd.conf,把启用 php5 的那一行,反注释掉,然后修改 DirectoryIndex,加上 index.php,然后创建 php 配置文件:

mv /etc/php.ini.default /etc/php.ini

重启 apache:

apachectl restart

3. 文档根目录在 /Library/WebServer/Documents,看了看 phpninfo 发现支持的扩展还不算太少 :-)

Filed under: Programming — Tags: , Comments (0)