Page 1 of 1

Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Sat Aug 25, 2018 2:38 am
by baxterdmutt
PHP is : 5.6.36-0+deb8u1
Serendipity Version 2.2.0-beta2

I've found a bug in the Clean-Blog template. When I click on 'preview' to preview a blog or comments I get this error:

Fatal error: Uncaught exception 'ErrorException' with message 'Warning: Parameter 2 to timeAgoInWords() expected to be a reference, value given' in /home/admin/web/mysite.tld/public_html/blog/templates_c/clean_blog/5d/24/34/5d2434559a2ba1c20fd8ba09cc03d18d799fdd6f_0.file.comments.tpl.php:91 Stack trace: #0 [internal function]: errorToExceptionHandler(2, 'Parameter 2 to ...', '/home/admin/web...', 91, Array) #1 /home/admin/web/mysite.tld/public_html/blog/templates_c/clean_blog/5d/24/34/5d2434559a2ba1c20fd8ba09cc03d18d799fdd6f_0.file.comments.tpl.php(91): call_user_func_array('timeAgoInWords', Array) #2 /home/admin/web/mysite.tld/public_html/blog/bundled-libs/Smarty/libs/sysplugins/smarty_template_resource_base.php(126): content_5b80a136768448_15781237(Object(Smarty_Internal_Template)) #3 /home/admin/web/mysite.tld/public_html/blog/bundled-libs/Smarty/libs/sysplugins/smarty_template_compiled.php(114): Smarty_Template_Resource_Base->getRenderedTemplateCode(Object(Smarty_Internal_Template)) #4 /hom in /home/admin/web/mysite.tld/public_html/blog/templates_c/clean_blog/5d/24/34/5d2434559a2ba1c20fd8ba09cc03d18d799fdd6f_0.file.comments.tpl.php on line 91
== ERROR-REPORT (BETA/ALPHA-BUILDS) ==

The solution is to edit 'templates/clean-blog/config.inc.php' and change the line:
function timeAgoInWords($params, &$smarty) {
to
function timeAgoInWords($params, $smarty) {

Any PHP version over 5.3 (I believe) does not allow this sort of reference. Strangely there are other references with the &$ and they don't seem to bother the app.

Hope this helps some other people. I'm not a PHP programmer so I kinda stumbled on this. It might not be the most elegant solution but it works well for me.

Roger

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Sat Aug 25, 2018 6:13 am
by Don Chambers
Happy to change this in the core if anyone else can confirm. I use this function in a few themes, so additional input will be greatly appreciated!

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Sat Aug 25, 2018 6:59 am
by baxterdmutt
If this helps - from the php manual:

“There is no reference sign on a function call - only on function definitions. Function definitions alone are enough to correctly pass the argument by reference. As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);.”

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Sat Aug 25, 2018 12:03 pm
by onli
But that's not the issue here. It's the place where references are allowed: A function definition. The issue is that it is not being given a reference, but a value. By the way, that collides with wthat the documentation is claiming, that PHP would handle that automatically by just declaring the reference in the funktion parameter definition. That doesn't work at all, not in PHP 5.6, anto in PHP 7.

The bug is actually a consequence from the smarty upgrade I did in the github master, the version you seem to be running. $smarty is a value now, not a reference. Thanks for testing! :)

Don, it would be great if you could fix that in the core, just change the function definition.

I was actually uncertain whether working with a value and not a reference would not break things, so it would be good to continue to test out whether everything still works as expected with this change.

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Sat Aug 25, 2018 3:14 pm
by Don Chambers
Can the fix be merely what Roger suggested, or does there need to be a conditional test on the php and/or smarty version?

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Sat Aug 25, 2018 6:10 pm
by baxterdmutt
onli wrote:
Sat Aug 25, 2018 12:03 pm
But that's not the issue here. It's the place where references are allowed: A function definition. The issue is that it is not being given a reference, but a value. By the way, that collides with wthat the documentation is claiming, that PHP would handle that automatically by just declaring the reference in the funktion parameter definition. That doesn't work at all, not in PHP 5.6, anto in PHP 7.

The bug is actually a consequence from the smarty upgrade I did in the github master, the version you seem to be running. $smarty is a value now, not a reference. Thanks for testing! :)
Thanks. I guess I just got lucky.

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Sat Aug 25, 2018 11:16 pm
by onli
Don Chambers wrote:
Sat Aug 25, 2018 3:14 pm
Can the fix be merely what Roger suggested, or does there need to be a conditional test on the php and/or smarty version?
Since it is a design in the core this can just be changed.

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Mon Aug 27, 2018 3:37 am
by Don Chambers
The core will be changed and will not require a theme change? Am I interpreting your response correctly?

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Mon Aug 27, 2018 2:58 pm
by onli
No, it will be necessary to change that function in the theme. But the theme is in the core, so in this case it can just be changed, without needing bc compatibility with earlier s9y versions.

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Tue Aug 28, 2018 1:44 am
by Don Chambers
Thanks. I'll change it in Cleanblog. I think its in Timeline too, also a core theme.

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Wed Sep 05, 2018 11:05 pm
by Don Chambers
I'm about to make this change....

Code: Select all

function timeAgoInWords($params, &$smarty) {
to this as recommended

Code: Select all

function timeAgoInWords($params, $smarty) {
I realize that changing this in the core means I don't need to worry about it working with older s9y versions, but it should still work in older versions of s9y... yes? no? I'm not a php coder, so not entirely sure about "reference" vs "value". :?

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Wed Sep 05, 2018 11:44 pm
by onli
Yes, I think that it should still work regardless. But I would not be confident enough to deploy the change to old s9y versions without testing.

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Thu Sep 06, 2018 1:58 am
by Don Chambers
onli wrote:
Wed Sep 05, 2018 11:44 pm
Yes, I think that it should still work regardless. But I would not be confident enough to deploy the change to old s9y versions without testing.
Nor would I. Just more of a curiosity question.

Re: Clean blog Warning: Parameter 2 to timeAgoInWords() expected to be a reference

Posted: Thu Sep 06, 2018 4:37 pm
by Don Chambers
Committed.