strlen() expects parameter 1 to be string, array given on validateAttributes

Hello,

I’m using yii 1.0.9 with windows + apache 2.2.12 + php 5.3.0 + mysql 5.1.37

After reinstalling my WAMP environment i started having problems with the validateAttributes method when using a activeCheckBoxList.

In my model I have set no rules for it, I just do convert it to a string using implode on beforeSave (if it is an array = if it is set) and then convert it back to an array using the afterFind method…

Maybe the problem has something to do with my new php.ini but setting should be ok… so… could this be due to a bug with the php 5.3.0 version?

More info about the error I get:


\yii\validators\CStringValidator.php(60)


00055:     protected function validateAttribute($object,$attribute)

00056:     {

00057:         $value=$object->$attribute;

00058:         if($this->allowEmpty && $this->isEmpty($value))

00059:             return;

00060: $length=strlen($value); 



thanks.

bye,

Giovanni.

…any advice?

thanks.

bye,

Giovanni.

Not sure I understand.

What if you convert to a string in beforeValidate()?

/Tommy

hi,

thanks for your reply… I’ve tried but now I get another error… here is beforeValidate my method:




	public function beforeValidate($scenario) {

		if (is_array($this->my_var)) {

			$this-> my_var =','.implode(",", $this-> my_var).',';

		}

		else {

			$this-> my_var ='';

		}


		return parent::beforeValidate($scenario);

	}

and the error that now I get is (but the record is being created in db):

[color="#FF0000"]htmlspecialchars() expects parameter 1 to be string, array given[/color]


\yii\web\helpers\CHtml.php(71)


00069:     public static function encode($text)

00070:     {

00071: return htmlspecialchars($text,ENT_QUOTES,Yii::app()->charset);

00072:     }




is there something wrong with the way I’ve extended the beforeValidate method? thanks.

bye,

Giovanni.

hello,

I’m sorry. the second error (“htmlspecialchars() expects parameter 1 to be string, array given”) is my fault as when it creates the record it redirects to an action that I’m not using… so don’t consider that one.

Your tip seems to have fixed it, thanks :)

anyway I’ve tried to install php 5.2.9 and saw that the problem was not there using it, so it is also due to 5.3.0 and probably to this:

"Parameter parsing API unification will cause some functions to behave more or less strict when it comes to type juggling"

http://www.php.net/releases/5_3_0.php

bye,

Giovanni.