Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Second parameter of the CHtml::value() doesn't support functions crea…

…ted by "create_function" anymore.
  • Loading branch information...
commit 694dcb885c5d536ae9d082649cea27dbaab20c85 1 parent a3ce4e7
@resurtm authored
16 framework/web/helpers/CHtml.php
@@ -1884,23 +1884,15 @@ public static function listData($models,$valueField,$textField,$groupField='')
* @param mixed $model the model. This can be either an object or an array.
* @param mixed $attribute the attribute name (use dot to concatenate multiple attributes)
- * or anonymous function (PHP 5.3+). Note that numeric value is meaningless when first parameter
- * is object typed.
+ * or anonymous function (PHP 5.3+). Remember that functions created by "create_function"
+ * are not supported by this method. Also note that numeric value is meaningless when
+ * first parameter is object typed.
* @param mixed $defaultValue the default value to return when the attribute does not exist.
* @return mixed the attribute value.
public static function value($model,$attribute,$defaultValue=null)
- // Why we're strictly comparing $attribute[0] with NULL character in the condition below?
- // This is needed to distinguish string returned by "create_function" and plain string which
- // was generated in the PHP code. "create_function" has very useful property/feature:
- // it returns string with prepended NULL character. Note that this is NOT a clumsy trick,
- // it's documented and known feature.
- // String created by "create_function": "{NULL}lambda_{XX}"
- // String generated in the PHP code: "some_string_without_NULLs"
- // (Using strings containing NULL bytes as attribute names does not make sense.)
- if(is_scalar($attribute) && $attribute[0]!==chr(0))
+ if(is_scalar($attribute))
foreach(explode('.',$attribute) as $name)
if(is_object($model) && isset($model->$name))
6 tests/framework/web/helpers/CHtmlTest.php
@@ -474,9 +474,9 @@ public function providerValue()
- // create_function
- array(array('k1'=>'v1','k2'=>'v2','v3','v4'),create_function('$model','return $model["k2"];'),null,'v2'),
- array((object)array('k1'=>'v1','k2'=>'v2','v3','v4'),create_function('$model','return $model->k2;'),null,'v2'),
+ // create_function is not supported by CHtml::value(), we're just testing this feature/property
+ array(array('k1'=>'v1','k2'=>'v2','v3','v4'),create_function('$model','return $model["k2"];'),null,null),
+ array((object)array('k1'=>'v1','k2'=>'v2','v3','v4'),create_function('$model','return $model->k2;'),null,null),
// standard PHP functions should not be treated as callables
Please sign in to comment.
Something went wrong with that request. Please try again.