Error with %session when $_SESSION contains objects (...)
bforchhammer - June 26, 2008 - 18:47
| Project: | Webform |
| Version: | 6.x-2.6 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
I tried to use %session in a hidden field and I got the following error message everytime I viewed the form:
Recoverable fatal error: Object of class stdClass could not be converted to string in webform\webform.module on line 2079.
I think I managed to track the error down to a $node-object which I accidentially stored in $_SESSION somewhere else in my application, and the error is caused by a str_replace call in webform.module; I guess a simple if (!is_object(...)) at the right place would solve the problem, but I'm not sure if that's the best way... ?

#1
The token replacement would also fail if it ran into an array unexpectedly. For the time being I've just caste the replacement to a string to ensure it'll be replaced properly.
#2
Automatically closed -- issue fixed for two weeks with no activity.
#3
If $value is not a string, $replace and $find mess up, as they won't contain the same number of elements.
The patch below inserts an empty string replacement string in order to keep the 2 arrays in line.
Index: webform/webform.module
===================================================================
--- webform/webform.module (revision 135)
+++ webform/webform.module (working copy)
@@ -2115,11 +2115,13 @@
if (is_string($value)) {
$replace[] = (string)$value;
}
+ else {
+ $replace[] = '';
+ }
}
}
}
}
-
$string = str_replace($find, $replace, $string);
// Clean up any unused tokens.
#4
This was corrected in the 2.7 version, which uses an entirely different replacement mechanism. Please reopen if the problem continues to exist.