zoghal / cakephp-MultiTranslateBehavior

extended Cakephp 2.1 TranslateBehavior for support save/edit/validate of Multi Language in Forms
19 stars 11 forks source link

PHP 5.3 isset behaviour #3

Closed MichaelKubovic closed 10 years ago

MichaelKubovic commented 11 years ago

Hello, I've noticed that isset($string) (expected array) returns always true.

Line: 102

if (!isset($row[$model->alias][$aliasField][$_locale]) && !empty($row[$model->alias]['i18n_' . $field . '_' . $_locale])) {

In my case $row[$model->alias][$aliasField] returns string.

from php.net

Example #2 isset() on String Offsets

$expected_array_got_string = 'somestring';
var_dump(isset($expected_array_got_string['some_key']));
var_dump(isset($expected_array_got_string[0]));
var_dump(isset($expected_array_got_string['0']));
var_dump(isset($expected_array_got_string[0.5]));
var_dump(isset($expected_array_got_string['0.5']));
var_dump(isset($expected_array_got_string['0 Mostel']));

Output of the above example in PHP 5.3: bool(true) bool(true) bool(true) bool(true) bool(true) bool(true)

I suggest to add this line before the condition to ensure that isset is checking an array.

$row[$model->alias][$aliasField] = array();
irongomme commented 11 years ago

Agree, unless adding this line, there are warnings because of the original field array is a string and not an array, so i've put this on line 100, just before "if (is_array($locale)) {" :

$row[$model->alias][$aliasField] = array();

So the field is replaced by the translation array

zoghal commented 10 years ago

@MichaelKubovic I'm starting work on a new version. Please in Milestone 2.5 announce everything that is needed to be added in the new version.