Strtoupper() expects parameter 1 to be string, object given in

Hi

I’m getting the above error when the I reach ->all() on the query builder. I’m not entirely sure why. I got the raw sql that the query generates, ran it and it runs fine. I noticed that my innerJoinWith is causing the problem although I’m not entirely sure why. File is: in

C:\xampp-7\htdocs\www\vendor\yiisoft\yii2\db\QueryBuilder.php:1546

VtCol::find()
          ->alias('V')
          ->innerJoinWith('site')
          //->innerJoinWith('cardNumber') -> Causes Error
          //->joinWith('pat')  -> Causes Error
          ->where(['V.DEL_DT' => null])
          ->andWhere(['<=', new Expression("TRUNC(TO_DATE(V.PRO_DATE, 'YYYYMMDD'))"), new Expression("TRUNC(TO_DATE('" . $quarterEndDate . "', 'YYYYMMDD'))")])
          ->andWhere(['V.FLWP_IND' => null])
          ->andWhere(['V.PASS_FOR_PAY' => null])
          ->andWhere(['V.SIGNED' => 'Y']) 
          ->all();

I’ve shown one of the relations here:

public function getCardNumber()
    {
        return $this->hasOne(CardNumber::className(), ['P_ID' => 'P_ID'])
                    ->andOnCondition(['CARD_NUMBER.CARD_TYPE_CD' => 35])
                    ->andOnCondition(['CARD_NUMBER.DEL_DT' => null]);
    }

But I’m still not entirely sure what the problem here is and wondered if anyone has any ideas?

Strtoupper() expects parameter 1 to be string, object given

This error message comes from the line 1546 of QueryBuilder.php. I guess it is the 2nd line in createConditionFromArray() method.

   public function createConditionFromArray($condition)
   {
       if (isset($condition[0])) { // operator format: operator, operand 1, operand 2, ...
            $operator = strtoupper(array_shift($condition));
            ...

It indicates that some of your operator format conditions has an error … the 1st parameter (operator) is an object instead of a string.

That’s all I can tell from the information given.

I would use a debugger to set a break point on the 1st line of createConditionFromArray and see what is in $condition.

1 Like

Is it allowed to use an expression for both operands of andWhere(['<=', ...? I think it expects the first operand to be a column name.

Try rewriting as

      ->andWhere(new Expression("something <= somethingelse"))

which is a little easier to read too.

I did find the problem and solution to this https://github.com/yiisoft/yii2/issues/17015
Essentially, when Oracle when accessing over a 1000 rows, it breaks the result set up into pages of a 1000s. On the 2nd way through this, it drops the operator parameter.

Fix was to use the dev-master branch until 2.0.16 is released

2 Likes