tags:

views:

84

answers:

3

i used to have a function defined like this (that is working fine under ubuntu 9.10):

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

after i have updated my machine to ubuntu 10.04( and php version Version: 5.3.2-1ubuntu4.2 ) my app starts to show an error like this one ==>

Fatal error: Method Application_Model_Person::__tostring() cannot take arguments in /home/speshu/Development/where/application/models/Person.php on line 39

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
+2  A: 
function __toString() {
    if(func_num_args()>0) {
        $surNameFirst=func_get_arg(0);
    } else {
        $surNameFirst=false;
    }
....

This is how I got around the problem, it's dirty and ugly... but it worked to get the system working again before finding a more permanent solution.

You should be able to figure out how best to extend this to suite your needs, be aware that it's probably best to pass in an assosiative array if using this method, as it would be easier to access the data.

ILMV
+6  A: 

As of version 5.3 The __toString magic method can no longer accept arguments.

In any case should you really be doing that with a magic method? Why not declare toString($whatever) instead?

Manos Dilaverakis
Indeed, if you need the possibility argument passed for a string representation, define a `function toString($arg='')`, and let `function __toString(){return $this->toString();}` to avoid duplication.
Wrikken
A: 

Another Possible work around.

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();
RobertPitt