CodeIgniter Forums
Deprecation warning in \Honeypot\Honeypot.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Deprecation warning in \Honeypot\Honeypot.php (/showthread.php?tid=88952)



Deprecation warning in \Honeypot\Honeypot.php - objecttothis - 12-08-2023

PHP 8.2.12
CI 4.4.3

I have the following code
PHP Code:
    public function getCsv(): DownloadResponse
    
{
        
$name 'import_customers.csv';
        
$data file_get_contents(WRITEPATH "uploads/$name");
        return 
$this->response->download($name$data);
    } 

When executed it produces the following deprecation warning. This warning is not present in PHP 8.0.x

Code:
WARNING - 2023-12-08 17:21:12 --> [DEPRECATED] str_ireplace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in SYSTEMPATH\Honeypot\Honeypot.php on line 93.
1 SYSTEMPATH\Honeypot\Honeypot.php(93): str_ireplace('</form>', '<div style="display:none"><label>Fill This Field</label><input type="text" name="honeypot" value=""/></div></form>', null)
2 SYSTEMPATH\Filters\Honeypot.php(53): CodeIgniter\Honeypot\Honeypot->attachHoneypot(Object(CodeIgniter\HTTP\DownloadResponse))
3 SYSTEMPATH\Filters\Filters.php(210): CodeIgniter\Filters\Honeypot->after(Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\DownloadResponse), null)
4 SYSTEMPATH\CodeIgniter.php(522): CodeIgniter\Filters\Filters->run('customers/csv', 'after')
5 SYSTEMPATH\CodeIgniter.php(361): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
6 FCPATH\index.php(79): CodeIgniter\CodeIgniter->run()



RE: Deprecation warning in \Honeypot\Honeypot.php - kenjis - 12-09-2023

Try this:

Code:
--- a/system/Honeypot/Honeypot.php
+++ b/system/Honeypot/Honeypot.php
@@ -89,7 +89,7 @@ class Honeypot

        $prepField = $this->prepareTemplate($this->config->template);

-        $bodyBefore = $response->getBody();
+        $bodyBefore = $response->getBody() ?? '';
        $bodyAfter  = str_ireplace('</form>', $prepField . '</form>', $bodyBefore);

        if ($response->getCSP()->enabled() && ($bodyBefore !== $bodyAfter)) {



RE: Deprecation warning in \Honeypot\Honeypot.php - objecttothis - 12-09-2023

Yep, that fixes it!


RE: Deprecation warning in \Honeypot\Honeypot.php - kenjis - 12-09-2023

I sent a PR to fix: https://github.com/codeigniter4/CodeIgniter4/pull/8316

The PR was merged. So this bug will be fixed in v4.4.4.