Make HTML_QuickForm_file rule methods static for PHP 8#150
Conversation
The file element registers four validation rules as callbacks via
HTML_QuickForm::registerRule('callback', ...), which stores them as
[class_name, method_name] pairs and later invokes them with
call_user_func. The methods (_ruleIsUploadedFile, _ruleCheckMaxFileSize,
_ruleCheckMimeType, _ruleCheckFileName) were declared as instance
methods even though they never reference $this. Under PHP 8 the
"call non-static method statically" pattern throws TypeError, aborting
file/blob uploads with:
Argument #1 ($callback) must be a valid callback, non-static method
HTML_QuickForm_file::_ruleCheckMaxFileSize() cannot be called statically
Mark all four rule methods static so the registered callbacks remain
valid under PHP 8. Existing $this-> call sites (e.g. isUploadedFile)
continue to work because static methods can be invoked via an instance.
Fixes #147
https://claude.ai/code/session_014nJbXsY9TdG5PXE2kBHRuV
|
i d/l'd both xataface/lib/HTML/QuickForm/file.php & hiddenselect.php, uploaded to hoadbbut still no joy-/ Fatal error: Uncaught TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, non-static method HTML_QuickForm_file::_ruleCheckMaxFileSize() cannot be called statically in /home/cardin55/public_html/hoaDB/xataface-29apr26/lib/HTML/QuickForm/Rule/Callback.php:66 Stack trace: #0 /home/cardin55/public_html/hoaDB/xataface-29apr26/lib/HTML/QuickForm/RuleRegistry.php(148): HTML_QuickForm_Rule_Callback->validate(Array, '12000000') #1 /home/cardin55/public_html/hoaDB/xataface-29apr26/lib/HTML/QuickForm.php(1536): HTML_QuickForm_RuleRegistry->validate('maxfilesize', Array, '12000000', true) #2 /home/cardin55/public_html/hoaDB/xataface-29apr26/Dataface/ShortRelatedRecordForm.php(739): HTML_QuickForm->validate() #3 /home/cardin55/public_html/hoaDB/xataface-29apr26/actions/new_related_record.php(90): Dataface_ShortRelatedRecordForm->validate() #4 /home/cardin55/public_html/hoaDB/xataface-29apr26/Dataface/Application.php(3723): dataface_actions_new_related_record->handle(Array) #5 /home/cardin55/public_html/hoaDB/xataface-29apr26/Dataface/Application.php(3866): Dataface_Application->handleRequest() #6 /home/cardin55/public_html/hoaDB/xataface-29apr26/Dataface/Application.php(3751): Dataface_Application->_display(false, false) #7 /home/cardin55/public_html/hoaDB/index.php(12): Dataface_Application->display() #8 {main} thrown in /home/cardin55/public_html/hoaDB/xataface-29apr26/lib/HTML/QuickForm/Rule/Callback.php on line 66 |
|
@airdrummer I can't reproduce on a test app. That error readout suggests that this fix wasn't applied. If you're still getting an error, please post in a new issue. |
The file element registers four validation rules as callbacks via
HTML_QuickForm::registerRule('callback', ...), which stores them as
[class_name, method_name] pairs and later invokes them with
call_user_func. The methods (_ruleIsUploadedFile, _ruleCheckMaxFileSize,
_ruleCheckMimeType, _ruleCheckFileName) were declared as instance
methods even though they never reference $this. Under PHP 8 the
"call non-static method statically" pattern throws TypeError, aborting
file/blob uploads with:
Argument #1 ($callback) must be a valid callback, non-static method
HTML_QuickForm_file::_ruleCheckMaxFileSize() cannot be called statically
Mark all four rule methods static so the registered callbacks remain
valid under PHP 8. Existing $this-> call sites (e.g. isUploadedFile)
continue to work because static methods can be invoked via an instance.
Fixes #147
https://claude.ai/code/session_014nJbXsY9TdG5PXE2kBHRuV