Coder Social home page Coder Social logo

Comments (5)

ADDISON74 avatar ADDISON74 commented on June 12, 2024

We missed this deprecation in the code. Here is the fix for it:

https://onlinephp.io/c/54a59

Good information related to this issue:

https://stackoverflow.com/questions/71707325/migration-to-php-8-1-how-to-fix-deprecated-passing-null-to-parameter-error-r

from magento-lts.

ADDISON74 avatar ADDISON74 commented on June 12, 2024

File: /app/code/core/Mage/GiftMessage/Block/Message/Inline.php on line 246.

    /**
     * Return escaped value
     *
     * @param string $value
     * @param string $defaultValue
     * @return string
     */
    public function getEscaped($value, $defaultValue = '')
    {
        return $this->escapeHtml(trim($value) != '' ? $value : $defaultValue);
    }

How would you like to proceed for this part of the code to fix this issue?

VARIANT 1

    public function getEscaped($value, $defaultValue = '')
    {
        $value = $value ?? '';
        return $this->escapeHtml(trim($value) != '' ? $value : $defaultValue);
    }

VARIANT 2

    public function getEscaped($value, $defaultValue = '')
    {
        return $this->escapeHtml(trim($value ?? '') != '' ? $value : $defaultValue);
    }

VARIANT 3

    public function getEscaped($value, $defaultValue = '')
    {
        return $this->escapeHtml((string) trim($value) != '' ? $value : $defaultValue);
    }

VARIANT 4

    public function getEscaped($value, $defaultValue = '')
    {
        return $this->escapeHtml((empty($value) ? '' : trim($value)) != '' ? $value : $defaultValue);
    }

VARIANT 5

    public function getEscaped($value, $defaultValue = '')
    {
        if (is_string($value)) {
            return $this->escapeHtml(trim($value) != '' ? $value : $defaultValue);
        }
    }

All the variants above solve the issue. Any feedback is welcome.

from magento-lts.

fballiano avatar fballiano commented on June 12, 2024

I'd do this:

public function getEscaped($value, $defaultValue = '')
{
    if ($value === null || strlen($value) == 0) return $defaultValue;
    return $this->escapeHtml(trim($value));
}

it seems to me easier to read and should give a tiny fraction more performance because it doesn't call functions that are not needed with an empty string.

PS: I think variant 5 doesn't work because it never returns the $defaultvalue for an empty $value

from magento-lts.

ADDISON74 avatar ADDISON74 commented on June 12, 2024

Your version is fine too. It is good to discuss before proposing a PR. such a change must take into account the non-alteration of performance, the ease of reading the code.

I would use { } with the condition, as if this has been done before (I am remembering well).

public function getEscaped($value, $defaultValue = '')
{
    if ($value === null || strlen($value) == 0) {
        return $defaultValue;
    }
    return $this->escapeHtml(trim($value));
}

To Be Discussed

  1. I searched the OpenMage code for the following string escapeHtml(trim($. I found a few more, but I didn't investigate further. Do you think we should change in different PR's those as a preventive measure?
  2. Such errors could not be automatically identified in the source code of a workflow?

from magento-lts.

fballiano avatar fballiano commented on June 12, 2024

right about the brakets, phpcs would have complained ehhehe

  1. nice idea, I think it could also be one single PR, expecially if it's not many places to fix
  2. I don't know enough about this but probably PHPStan with a "higher level" configuration would detect those (among many many other errors) but we couldn't raise the level because of the many errors it triggers...

from magento-lts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.