在这里学到很多东西:
[url]http://www.w3pop.com/learn/view/p/3/o/0/doc/php5_oo_class_obj/[/url]
需要把php4升级到php5


[url]http://www.php.net/downloads.php[/url]
php-5.2.9.tar.gz

tar -zxvf php-5.2.9.tar.gz -C /usr/local/src
cd php-5.2.9

./configure --prefix=/usr/local/php5 \
> --with-apxs2=/usr/local/apache2/bin/apxs \
> --with-mysql=/usr/local/mysql \
> --with-config-file-path=/usr/local/php5

make; make install


网上说要下载libxml2
[url]ftp://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/[/url]
libxml2-2.6.12.tar.gz

tar -zxvf libxml2-2.6.12.tar.gz -C /usr/local/src
cd libxml2-2.6.12

./configure --prefix=/usr/local/libxml2 -enable-xml \
> --with-dom=/usr/local/include/libxml2 \
> --with-dom-xslt=/usr/local/include/libxsl \
> --with-libxml-dir=/usr/local/include/libxml

make; make install

vi /usr/local/apache2/conf/httpd.conf

找到第232-234行:


LoadModule php4_module        modules/libphp4.so
LoadModule php5_module        modules/libphp5.so

修改成:
#LoadModule php4_module        modules/libphp4.so
LoadModule php5_module        modules/libphp5.so


重启 apache
/usr/local/apache2/bin/apachectl stop
/usr/local/apache2/bin/apachectl start
 

vi /usr/local/apache2/htdocs/test3.php
<?php
phpinfo();
?>
浏览器里输入[url]http://localhost/test3.php[/url]
显示版本为:PHP Version 5.2.9

vi /usr/local/apache2/htdocs/class3.php
<?php
class Bike
{
public $color = "blue";
public $price = 200;
}
$myBike = new Bike();
echo "自行车的颜色为".$myBike->color."<br />";
echo "自行车的价格为".$myBike->price;
?>

浏览器里输入[url]http://localhost/class3.php[/url]

参考文章
[url]http://www.neo.com.tw/archives/211[/url]