Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
output:b_test has a value of false
foo({ b_live: 1, b_test: , cmd: "test" });
foo({ b_live: 1, b_test: , cmd: "test" });
a test module for this bug:
function testjs_help($section = 'admin/help#tangible') {
switch ($section) {
case 'admin/modules#description':
return t('test drupal_call_js function');
}
}
function testjs_menu($cache){
if($cache){
$items[] = array('path' => 'testjs', 'title' => t('test js'),
'callback' => 'testjs_page', 'access' => TRUE);
}
return $items;
}
function testjs_page(){
$parray = array('b_live'=>true,'b_test'=>false,'cmd'=>'test');
$output = drupal_call_js('foo',$parray);
$pobject = new Stdclass();
$pobject->b_live=true;
$pobject->b_test=false;
$pobject->cmd='test';
$output .= drupal_call_js('foo',$pobject);
print theme('page',$output);
return ;
}
Comment | File | Size | Author |
---|---|---|---|
#2 | js-cast.patch | 585 bytes | Dries |
Comments
Comment #1
Dries CreditAttribution: Dries commentedDoes this affect any of the existing functionality, or only custom functionality or contributed modules?
What is Javascript's equivalent of PHP's FALSE? Any reference?
Comment #2
Dries CreditAttribution: Dries commentedThe problem is this:
It prints:
The following seems to work though:
It prints:
Patched attached. Might be a more elegant way though.
Comment #3
simeI replicated the problem, and then fixed it with the patch.
I also googled the problem for other solutions. Only a couple of references to the "behaviour" were found, and no better solution was found.
Comment #4
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedShouldn't we add the cast for all cases?
Comment #5
Dries CreditAttribution: Dries commentedkilles: I don't think so. The problem is with implode() not dealing properly with boolean types. The other types should work fine. If in doubt, write a quick test case like I did.
Comment #6
Steven CreditAttribution: Steven commentedErr I don't see how implode is involved. PHP just always converts false to the empty string when you cast it to string (e.g. using print, implode, ...). The proper solution is to output 'true' and 'false' instead to preserve the boolean type.
Committed a different patch to HEAD.
Comment #7
simeQuick help please.
How do I review what you committed? The closest I've found is http://drupal.org/project/cvs/3060, but I don't see anything relevant, so am I missing something?
Comment #8
Steven CreditAttribution: Steven commentedWas not committed due to sleepy head. Committed for real now.
Comment #9
(not verified) CreditAttribution: commented