Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
580 views
in Q2A Core by

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
by

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.

by
edited by
Thanks pupi1985 for your reply. However, error actually occurs in PHP 7.1.2. This function has to be improved.
Basis that I claim:
https://wiki.php.net/rfc/invalid_strings_in_arithmetic
by
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
by
Already reported with fix suggestions:

https://github.com/q2a/question2answer/issues/503
by
This has been fixed in the 1.8 branch.
...