Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Bug of qa_get_max_upload_size() function

+4 votes
asked Aug 14, 2017 in Q2A Core by sama55

Usually, no error occurs. However, it will be error in a specific environment. This line depends on the special specification of PHP. It is very fragile.

$minphp *= 1024;  // minphp is "xxG / xxM / xxK"

2 Answers

+1 vote
answered Aug 14, 2017 by pupi1985

I don't really think there can be an error in the qa_get_max_upload_size(). Indeed the $minphp variable can have a string such as "xM". The thing is that given the dynamic nature of the PHP language, it manages to juggle with the types and perform a string to number conversion. In short, it takes all digits up to the G/M/K and then multiplies it by 1024.

Indeed it is a bit dirty, IMO, but I don't really think it can result in any bug (or at least I can't think of any input that would break the function and generate an unexpected result).

In fact, PHP guys actually suggested a very similar approach.

There is just a silly thing, though (which even happens on the approach suggested in the documentation). The output value of that function can be either a (numeric) string or a number. In general, this shouldn't be an issue (because of the type juggling) but it can be prevented by casting it before returning the value.

commented Aug 14, 2017 by sama55
edited Aug 14, 2017 by sama55
Thanks pupi1985 for your reply. However, error actually occurs in PHP 7.1.2. This function has to be improved.
Basis that I claim:
commented Aug 14, 2017 by pupi1985
Interesting. I'm not quite up-to-date with the new changes in latest PHP versions. Anyway, the output of the function won't change. The only issue would be a few extra lines in the log (the notices). I agree with you anyway. It should be updated
+3 votes
answered Aug 14, 2017 by q2apro
Already reported with fix suggestions:

commented Aug 15, 2017 by Scott
This has been fixed in the 1.8 branch.