代码之家  ›  专栏  ›  技术社区  ›  jspeshu

php5魔术函数\uuToString($param=null)不能接受参数

  •  1
  • jspeshu  · 技术社区  · 15 年前

    public function __toString( $surNameFirst = false) { 
         if ($this->givenName . $this->surname == '') return null;
         else .......
    }
    

    在我将我的机器更新到ubuntu10.04(和php版本:5.3.2-1ubuntu4.2)之后 )我的应用程序开始显示这样的错误==>

    Call Stack:
        0.0001     616576   1. {main}() /home/speshu/Development/where/public/index.php:0  
        0.0294    1008248   2. Zend_Application->bootstrap() /home/speshu/Development/where/public/index.php:35
        0.0294    1008328   3. Zend_Application_Bootstrap_BootstrapAbstract->bootstrap() /usr/local/lib/ZendFramework-1.10.0/library/Zend/Application.php:355
        0.0294    1008328   4. Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap() /usr/local/lib/ZendFramework-1.10.0/library/Zend/Application/Bootstrap/BootstrapAbstract.php:582
        0.0387    1991416   5. Zend_Application_Bootstrap_BootstrapAbstract->_executeResource() /usr/local/lib/ZendFramework-1.10.0/library/Zend/Application/Bootstrap/BootstrapAbstract.php:618
        0.0387    1991776   6. Bootstrap->_initDoctrineCLI() /usr/local/lib/ZendFramework-1.10.0/library/Zend/Application/Bootstrap/BootstrapAbstract.php:665
        0.0387    1991856   7. Bootstrap->_initDoctrine() /home/speshu/Development/where/application/Bootstrap.php:66
        0.0406    2245200   8. Doctrine_Core::loadModels() /home/speshu/Development/where/application/Bootstrap.php:93
    
    4 回复  |  直到 15 年前
        1
  •  8
  •   Manos Dilaverakis    9 年前

    The __toString magic method can no longer accept arguments .

    在任何情况下,你真的应该用一种神奇的方法去做吗?为什么不声明toString($whatever)呢?

        2
  •  2
  •   Ben Everard    15 年前
    function __toString() {
        if(func_num_args()>0) {
            $surNameFirst=func_get_arg(0);
        } else {
            $surNameFirst=false;
        }
    ....
    

    您应该能够找出如何最好地扩展它以满足您的需要,请注意,如果使用此方法,可能最好传入一个关联数组,因为这样更容易访问数据。

        3
  •  2
  •   Hugo Ferreira    11 年前

    我认为调用$obj->__toString();

        4
  •  0
  •   RobertPitt    15 年前

    class test
    {
        var $toStringArgs = array();
    
        function SetToStringArgs()
        {
           $this->toStringArgs = func_get_args();
        }
    
        function __toString()
        {
             var_dump($this->toStringArgs);
        }
    }
    
    $test = new test();
    
    $test->SetToStringArgs('firstname','lastname');
    
    $test->__toString();
    
    推荐文章