0

I'm having problem when trying to send SMTP mail via cakephp3 with php 7.4

Notice: Notice (8): compact() [<a href='http://php.net/function.compact'>function.compact</a>]: Undefined variable: etagMatches in [/home/vendor/cakephp/cakephp/src/Network/Response.php, line 1281]

The function look like this:

 public function checkNotModified(Request $request)
    {
        $etags = preg_split('/\s*,\s*/', $request->header('If-None-Match'), null, PREG_SPLIT_NO_EMPTY);
        $modifiedSince = $request->header('If-Modified-Since');
        if ($responseTag = $this->etag()) {
            $etagMatches = in_array('*', $etags) || in_array($responseTag, $etags);
        }
        if ($modifiedSince) {
            $timeMatches = strtotime($this->modified()) === strtotime($modifiedSince);
        }
        $checks = compact('etagMatches', 'timeMatches');
        if (empty($checks)) {
            return false;
        }
        $notModified = !in_array(false, $checks, true);
        if ($notModified) {
            $this->notModified();
        }

        return $notModified;
    }

Is there any solution? (it was working fine before I don't know what changed)

Farouk
  • 23
  • 1
  • 6
  • 1
    Those two variables are only defined IF they go into the `if` block. If they don't go into those blocks, then those variables are not defined. Give them default values first. – aynber May 02 '23 at 13:11
  • You can provide an example? – Farouk May 03 '23 at 09:51
  • 1
    Upgrade your CakePHP dependency to at least 3.6.13. https://github.com/cakephp/cakephp/issues/12536 – ndm May 03 '23 at 10:34
  • 1
    It's as simple as `$etagMatches = false; $timeMatches = false;` at the top of the function. – aynber May 03 '23 at 11:52
  • Thanks guys, The solution is (disable SMTP restriction on WHM) – Farouk May 04 '23 at 11:40

0 Answers0