fender0107401 发表于 2013-04-11 17:30

PHP是不是没法再class的外面定义method?

那也太不方便了。:mrgreen:

bikong0411 发表于 2013-04-12 08:53

啥意思????

fender0107401 发表于 2013-04-12 09:01

回复 2# bikong0411

就是说我定义一个类(foo),

然后定义了几个函数(foo_method_01(), foo_method_02()),但是这2个函数比较长,我想单独放在一个文件里面不想和foo放在一起。

bikong0411 发表于 2013-04-12 09:28

可以啊
$ cat b.php
<?php
function t()
{
        echo "W";
}

$ cat a.php
<?php
require 'b.php';
class A
{
        function test()
        {
                t();
        }
}
$a=new A();
$a->test();

$ php a.php
W

fender0107401 发表于 2013-04-12 10:25

回复 4# bikong0411

这个明显不算啊,你的test是在class内部定义好的,然后只是调用了一下外部的函数,这个不能算是在class外面定义test吧。
   

bikong0411 发表于 2013-04-12 17:01

回复 5# fender0107401


    x,我说的是外面定义个t,哪说是test了

fender0107401 发表于 2013-04-12 17:05

回复 6# bikong0411

我就想去外边定义test,哈哈。 :mrgreen:


   

xinglu1983 发表于 2013-04-15 13:37

可以用继承。

pianist_cu 发表于 2013-04-15 14:46

别钻牛角尖
页: [1]
查看完整版本: PHP是不是没法再class的外面定义method?