Code Monkey home page Code Monkey logo

Comments (6)

ghostwriter avatar ghostwriter commented on June 14, 2024 1

good point.

For the record I was trying to find a solution to the particular issue. Iā€™m not against adding mbstring.

from laminas-cache.

ghostwriter avatar ghostwriter commented on June 14, 2024

Actually you may not need the mbstring extension:

if (strlen($string) != strlen(utf8_decode($string)))
{
    echo 'string is unicode';
}

from laminas-cache.

boesing avatar boesing commented on June 14, 2024

@ghostwriter As written in Slack, this would then require ext-xml.

from laminas-cache.

ghostwriter avatar ghostwriter commented on June 14, 2024

@boesing right.

also came up with this:

if (strlen($string) !== strlen(html_entity_decode($string, ENT_QUOTES , 'ISO-8859-1')))
{
    echo 'string is unicode';
}
// another method

html_entity_decode is an internal function. https://3v4l.org/UZOM1

var_dump(in_array('html_entity_decode', get_defined_functions()['internal'])); // bool(true)

from laminas-cache.

boesing avatar boesing commented on June 14, 2024

The main thing I dont like here is, that strlen is slow depending on the key length. Here, we have to do it twice.

There were performance checks in #154 (comment) regarding performance and thus I'd like to avoid doing it twice. Thus, requiring mbstring seems the most proper way of veryfing the length of a string with a minimal footprint.

from laminas-cache.

boesing avatar boesing commented on June 14, 2024

Closing this with the rationale, that allowing keys longer than 65534 will lead to performance problems when validating cache keys. Another reason is, that mb_strlen does not return the byte length but the string length.
UTF-8 characters which consume 4-bytes should be treated as 4 characters but with mb_strlen they're treated as 1 character.

from laminas-cache.

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.