views:

16

answers:

1

I need to JSONize some data without quotes around the values for Javascript purposes.

I am following examples like

$data = array(
    'onClick' => new Zend_Json_Expr('function() {'
              . 'alert("I am a valid javascript callback '
              . 'created by Zend_Json"); }'),
    'other' => 'no expression',
);
$jsonObjectWithExpression = Zend_Json::encode(
    $data,
    false,
    array('enableJsonExprFinder' => true)
);

and then returning the $jsonObjectWithExpression, but I get an exception

Fatal error: Call to undefined function Zend_Json_Expr() in ...

I'm pretty sure my version 1.10.8 supports this feature, since I can see the class in json/Expr.php

Do I need to import/include this class somehow? I haven't had to import any other Zend classes..

A: 

Are you sure you're using the new keyword?

The error message seems to state you're attempting to call a function named Zend_Json_Expr

Phil Brown
...and that would be it. I feel stupid, since I lost a couple hours on that one. In my defense, the docs exclude 'new'.
Erik
It would have been slightly more obvious if you'd actually pasted in your code as your question does not contain any errors. The API (http://framework.zend.com/apidoc/core/Zend_Json/Expr/Zend_Json_Expr.html) is incorrect however the manual (http://framework.zend.com/manual/en/zend.json.advanced.html#zend.json.advanced.expr) is not
Phil Brown