gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

OODBBean::__toString() implementation only works with C_ERR_IGNORE #512

Closed Bernhard---H closed 8 years ago

Bernhard---H commented 8 years ago

The implementation of the method RedBeanPHP\OODBBean::__toString() only works as intended if \R::setErrorHandlingFUSE(\RedBeanPHP\OODBBean::C_ERR_IGNORE); is set.

If a model class doesn't implement the __toString() method, the RedBeanPHP\OODBBean::__call() method will at least cause (possible confusing) spam in in the log files or fail unexpectedly.

And even worse, in case of \RedBeanPHP\OODBBean::C_ERR_EXCEPTION php will fail with

PHP Fatal error: Method RedBeanPHP\OODBBean::__toString() must not throw an exception

and no hint on how to debug that.


I temporarily fixed it in the method RedBeanPHP\OODBBean::__call() by adding the __toString method to the whitelist:

if ( in_array( $method, array( '__toString', 'update', 'open', 'delete', 'after_delete', 'after_update', 'dispense' ), TRUE ) ) {
    return NULL;
}

But I have no idea if that destroys anything else.

gabordemooij commented 8 years ago

Sorry for the delay - I had some trouble at work and I started my own company. I'll look into this.

gabordemooij commented 8 years ago

Fixed in c2520bbc3e6e68e78eff4af0acede9e93ab296b1