Ask your Symfony questions! Pay money and get answers fast! (more info)

Fatal error: Object of class Criteria could not be converted Symfony

  • SOLVED

I get thiss error:

Warning: Illegal offset type in isset or empty in /usr/share/php/symfony/vendor/propel/util/Criteria.php on line 345

Catchable fatal error: Object of class Criteria could not be converted to string in /usr/share/php/symfony/vendor/propel/util/Criteria.php on line 1212


I just added this to my peeer class:


public static function getViaTextId( $id, $state = null, $con = null) {
if( empty($id) ) return false;

// if ($con === null) {
// $con = Propel::getConnection(self::DATABASE_NAME);
// }

$textid = mysql_real_escape_string($id);

//print_r( $textid);
//$sc = Connector::getInstance();

//if( empty($prefix) )
// $prefix = SF_PRODUCT;
// $website = $prefix;
// Are we in preview mode?
// $preview = $sc->GetForSite($website, 'CONTENT_PREVIEW',1);

$preview = '';

if(SF_ENVIRONMENT != 'prod') $preview = '1';

// echo '<br>preview is: '.$preview;

$c = new Criteria();
$c->add(FireBrickContentPeer::TEXTID, $textid);
$today = date("Y-m-d G:i:s");

if ($preview ) {
$c->add(FireBrickContentPeer::STATE, 'W');
//print_r($criteria1);
} else {
$c->add(FireBrickContentPeer::STATE, 'P');
$criteria2 = $c->getNewCriterion(FireBrickContentPeer::LIVE_DATE, '0000-00-00 00:00:00');
$criteria3 = $c->getNewCriterion(FireBrickContentPeer::LIVE_DATE, $today, Criteria::LESS_EQUAL);
// Perform OR at level 1 ($criteria2 $criteria3 )
$criteria2->addOr($criteria3);

// Perform AND at level 0 ($criteria1 $criteria2 )
$c->addAnd($criteria2);
print_r($c);
}
//echo 'do i even reach here?';
//$criteria0->addAnd($criteria1);
//echo 'here is the problem';
// $criteria1->addDescendingOrderByColumn(FireBrickContentPeer::LIVE_DATE);

print_r($c);

$v = FireBrickContentPeer::doSelectOne($c);

//print_r($v);
return $v;
//return !empty($v) ? $v : null;
}


The errror occurs on this line:

$v = FireBrickContentPeer::doSelectOne($c);

This is on a site runnning Symfony 1.0.

Waht cuase this error?

--------------------------

NEW INFO:

if i comment out everything except:

$c = new Criteria();
$v = FireBrickContentPeer::doSelectOne($c);


i still get the error.

I thought this was because the function was declared as 'static', but i changed that it is not static anymore. I still get the error:

Catchable fatal error: Object of class Criteria could not be converted to string in /usr/share/php/symfony/vendor/propel/util/Criteria.php on line 354

This mehtod gets called twice on the page. It works the first time, but it dies the second time.

What happens when a class has static methodss that call non-static methods that instantiate objects?


---------------------------------

update:

The error claims to happen in this core class:

/usr/share/php/symfony/vendor/propel/util/Criteria.php

here:

[CODE] public function getCriterion($column)
{
print_r($this->map);
if (isset($this->map[$column])) {
return $this->map[$column];
}
}[/CODE]


my print_r gives me:



[CODE]Array
(
[firebrick_content.CONTENT_TYPE] => Criterion Object
(
[value:private] => 37
[comparison:private] => =
[table:private] => firebrick_content
[realtable:private] => firebrick_content
[column:private] => CONTENT_TYPE
[ignoreStringCase:private] =>
[db:private] => DBMySQL Object
(
)

[clauses:private] => Array
(
)

[conjunctions:private] => Array
(
)

[parent:private] =>
)

[firebrick_content.STATE] => Criterion Object
(
[value:private] => P
[comparison:private] => =
[table:private] => firebrick_content
[realtable:private] => firebrick_content
[column:private] => STATE
[ignoreStringCase:private] =>
[db:private] => DBMySQL Object
(
)

[clauses:private] => Array
(
)

[conjunctions:private] => Array
(
)

[parent:private] =>
)

[firebrick_content.LIVE_DATE] => Criterion Object
(
[value:private] => 0000-00-00 00:00:00
[comparison:private] => =
[table:private] => firebrick_content
[realtable:private] => firebrick_content
[column:private] => LIVE_DATE
[ignoreStringCase:private] =>
[db:private] => DBMySQL Object
(
)

[clauses:private] => Array
(
[0] => Criterion Object
(
[value:private] => 2010-05-06 15:10:33
[comparison:private] => <=
[table:private] => firebrick_content
[realtable:private] => firebrick_content
[column:private] => LIVE_DATE
[ignoreStringCase:private] =>
[db:private] => DBMySQL Object
(
)

[clauses:private] => Array
(
)

[conjunctions:private] => Array
(
)

[parent:private] =>
)

)

[conjunctions:private] => Array
(
[0] => OR
)

[parent:private] =>
)

)[/CODE]

which is weird, since i comment out all code, and the mehtod no longer static

Answers (4)

2010-05-06

Bill Hunt answers:

I think this might be a bug in the old version of Propel. It looks like there's an issue with calling Criteria->getNewCriterion, the error on 1212 appears to be trying to parse the instance of Criteria as a string, thus the error. If you refactor to skip using that function, and stick to ->add(), I think it'll work.

The second error is probably because it's trying to call Criteria's iterator against a nonexistant set of criteria, and breaking.

2010-05-06

Eduardo Raffoul answers:

┬┐Would you show me your schema.yml? There's something that may be, but im not sure.

When you type
$c->add(FireBrickContentPeer::TEXTID, $textid);


It may be should be FireBrickContentPeer::TEXT_ID


art comments:

No, it is TEXTID. I wouldd get "No defined CONSTANT" iff otherwise

2010-05-06

Ender Technology answers:

AFAIK there is no need to call $textid = mysql_real_escape_string($id); because all input is automatically escaped. You may be double-escaping which is resulting in this error. Further, one of the main advantages of using the ORM interface is that it offers you a stronger potential database portability and adding mysql-specific commands to the code essentially destroys that advantage.

Rob O.
Ender Tech Corp.
[[LINK href="http://www.endertech.com"]]www.endertech.com[[/LINK]]


Ender Technology comments:

<blockquote>I thought this was because the function was declared as 'static', but i changed that it is not static anymore.</blockquote>

Those methods need to be static. Assuming that you changed it in the user's version of the model classes please post what that method contains.

Rob O.
Ender Tech Corp.
[[LINK href="http://www.endertech.com"]]www.endertech.com[[/LINK]]

2010-05-06

Jakub Zalas answers:

Are you sure it comes from the method you're debugging? Have you tried commenting its calls completely? I feel like fatal error is caused by a different part of your code.


art comments:

not sure how to test. method called twice. works the first time. if I comment out the code in the method then the page dies on the first call, and i never get to see what the 2nd call would look like


Jakub Zalas comments:

Are these calls next to each other in code? Or spread somewhere? Try commenting both calls. Maybe it's something else.


art comments:

Undid 'static'. No more static calls.

Tried putting line after, code dies, line never gets called. Code dies on that line, for sure. Never makes it past that line.


Jakub Zalas comments:

How is that your code dies in getCriterion() when you never call it?


Jakub Zalas comments:

Do you use the latest symfony 1.0 release? If not than try to upgrade.