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

Found a bug? Tell us!!
Post Reply
baxterdmutt
Regular
Posts: 5
Joined: Wed Aug 22, 2018 12:01 am

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

Post by baxterdmutt » Sat Aug 25, 2018 2:38 am

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

User avatar
Don Chambers
Regular
Posts: 3611
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

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

Post by Don Chambers » Sat Aug 25, 2018 6:13 am

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!

baxterdmutt
Regular
Posts: 5
Joined: Wed Aug 22, 2018 12:01 am

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

Post by baxterdmutt » Sat Aug 25, 2018 6:59 am

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);.”

User avatar
onli
Regular
Posts: 2160
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

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

Post by onli » 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! :)

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.

User avatar
Don Chambers
Regular
Posts: 3611
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

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

Post by Don Chambers » 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?

baxterdmutt
Regular
Posts: 5
Joined: Wed Aug 22, 2018 12:01 am

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

Post by baxterdmutt » Sat Aug 25, 2018 6:10 pm

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.

User avatar
onli
Regular
Posts: 2160
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

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

Post by onli » Sat Aug 25, 2018 11:16 pm

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.

User avatar
Don Chambers
Regular
Posts: 3611
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

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

Post by Don Chambers » Mon Aug 27, 2018 3:37 am

The core will be changed and will not require a theme change? Am I interpreting your response correctly?

User avatar
onli
Regular
Posts: 2160
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

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

Post by onli » Mon Aug 27, 2018 2:58 pm

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.

User avatar
Don Chambers
Regular
Posts: 3611
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

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

Post by Don Chambers » Tue Aug 28, 2018 1:44 am

Thanks. I'll change it in Cleanblog. I think its in Timeline too, also a core theme.

User avatar
Don Chambers
Regular
Posts: 3611
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

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

Post by Don Chambers » Wed Sep 05, 2018 11:05 pm

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". :?

User avatar
onli
Regular
Posts: 2160
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

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

Post by onli » 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.

User avatar
Don Chambers
Regular
Posts: 3611
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

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

Post by Don Chambers » Thu Sep 06, 2018 1:58 am

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.


Post Reply