Ticket #466: fORM::tablize() warnings and failure on call to fGrammar

Reporter: vena Type: defect Opened: 2 months ago Status: closed
Assigned to: wbond Priority: major Modified: 2 months ago Resolution: fixed

example code:

ini_set('display_errors', 1);
error_reporting(E_ALL|E_STRICT);
 
define('BASEPATH', rtrim(realpath('.'), '\\/') . '/');
 
function autoloadFlourish($class){
    if(file_exists(BASEPATH . '/libraries/flourish/' . $class . '.php')){
        include BASEPATH . '/libraries/flourish/' . $class . '.php';
        return true;
    }
}
spl_autoload_register('autoloadFlourish');
 
fCore::enableErrorHandling('html');
fCore::enableExceptionHandling('html');
 
class GalleryModel extends fActiveRecord
{
    public function configure(){}
}
 
$db = new fDatabase(...);
 
fORMDatabase::attach($db);
 
fORM::mapClassToTable('GalleryModel', 'sl_galleries');
 
$object = new GalleryModel();
$table = fORM::tablize($object);
echo $table;

Results in the following:

Context
-------

$_SERVER: Array
(
    [ACCEPTED_ENC] => gzip
    [HTTP_HOST] => xxx
    [HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
    [HTTP_ACCEPT_ENCODING] => gzip,deflate
    [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
    [HTTP_KEEP_ALIVE] => 115
    [HTTP_CONNECTION] => keep-alive
    [HTTP_COOKIE] => PHPSESSID=31054908187a3ac86277297a4282ea8d
    [PATH] => /usr/local/bin:/usr/bin:/bin
    [SERVER_SIGNATURE] => <address>Apache/2.2.12 (Ubuntu) Server at xxx Port 80</address>
  
    [SERVER_SOFTWARE] => Apache/2.2.12 (Ubuntu)
    [SERVER_NAME] => xxx
    [SERVER_ADDR] => 192.168.1.111
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 208.105.1.10
    [DOCUMENT_ROOT] => /
    [SERVER_ADMIN] => webmaster@localhost
    [SCRIPT_FILENAME] => /test.php
    [REMOTE_PORT] => 50500
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => {empty_string}
    [REQUEST_URI] => /test.php
    [SCRIPT_NAME] => /test.php
    [PHP_SELF] => /test.php
    [REQUEST_TIME] => 1279058629
    [argv] => Array
        (
        )
  
    [argc] => 0
)

$_POST: Array
(
)

$_GET: Array
(
)

$_FILES: Array
(
)

$_SESSION: {null}

$_COOKIE: Array
(
    [PHPSESSID] => xxx
)

Warning
-------
{doc_root}/test.php(36): fORM::tablize(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fORM.php(1127)
Illegal offset type in isset or empty

Warning
-------
{doc_root}/test.php(36): fORM::tablize(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fORM.php(1128): fGrammar::pluralize(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fGrammar.php(433)
Illegal offset type in isset or empty

Recoverable Error
-----------------
{doc_root}/test.php(36): fORM::tablize(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fORM.php(1128): fGrammar::pluralize(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fGrammar.php(440): fGrammar::splitLastWord(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fGrammar.php(590): strpos(Object(GalleryModel), ' ')
[internal function]
Object of class GalleryModel could not be converted to string

Notice
------
{doc_root}/test.php(36): fORM::tablize(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fORM.php(1128): fGrammar::pluralize(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fGrammar.php(440): fGrammar::splitLastWord(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fGrammar.php(590): strpos(Object(GalleryModel), ' ')
[internal function]
Object of class GalleryModel to string conversion

Warning
-------
{doc_root}/test.php(36): fORM::tablize(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fORM.php(1128): fGrammar::pluralize(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fGrammar.php(440): fGrammar::splitLastWord(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fGrammar.php(595): fGrammar::underscorize(Object(GalleryModel))
{doc_root}/libraries{doc_root}/flourish{doc_root}/fGrammar.php(735)
Illegal offset type in isset or empty


Fatal error: Cannot use object of type GalleryModel as array in /libraries/flourish/fGrammar.php on line 740

Attachments

History

Reply 07/13/10 20:43:40 changed by vena

sorry, forgot to mention this occurs in r864 even though that trace above is running r855.

Reply 07/14/10 23:38:24 changed by wbond

  • status changed from new to closed.
  • resolution set to fixed.

I fixed this in r866 by correcting the incorrect documentation. fORM::tablize() used to accept an object, but the method is used quite extensively throughout the ORM, and I found from some profiling that I was able to improve the performance by requiring that the parameter be a string rather than a string or object.

I understand that this makes the API a little harder to use, but my current belief is that it is the right decision.

Edit the Ticket



please register or log in to allow for editing your comment

Action