Code Monkey home page Code Monkey logo

Comments (4)

terrafrost avatar terrafrost commented on August 14, 2024

The concern I'd have with that is mcrypt_compat being loaded twice. phpseclib used to have issues with it being included twice:

phpseclib/phpseclib#217

random_compat works similarly to mcrypt_compat:

https://github.com/paragonie/random_compat/blob/master/lib/random.php

Mind you, whereas mcrypt_compat just does one if check before defining everything random_compat does if checks for everything.

from mcrypt_compat.

ivanweiler avatar ivanweiler commented on August 14, 2024

Hello all, I want to add check in legacy app, something like:

if(extension_loaded('mcrypt') || $hasMcryptCompat) {
//use mcrypt functions
} else {
//do something else
}

I can also use function_exists() ofc, but detecting mcrypt_compat would be better solution.
Anyway, maybe solution to both problems (how to detect mcrypt_compat, or not load it twice) would be to add something like
define('PHPSECLIB_MCRYPT_COMPAT', true) to mcrypt_compat ?

This way mcrypt_compat can detect if it's already loaded, it can use extension_loaded('mcrypt') and we can detect that we have it.

Just a suggestion, thx for great polyfill !!

from mcrypt_compat.

terrafrost avatar terrafrost commented on August 14, 2024

phpseclib does three different tests in different places:

if (!defined('MCRYPT_MODE_ECB')) {
...
if (!function_exists('phpseclib_mcrypt_list_algorithms')) {
...
if (!function_exists('mcrypt_list_algorithms')) {

The only one that PHPSECLIB_MCRYPT_COMPAT would be a viable solution would be !function_exists('phpseclib_mcrypt_list_algorithms') and idk that it's any better than `PHPSECLIB_MCRYPT_COMPAT?

For your own check you could do !function_exists('phpseclib_mcrypt_list_algorithms') yourself?

from mcrypt_compat.

glensc avatar glensc commented on August 14, 2024

I agree with @terrafrost here, that you should anyway test the feature (function exists, constant exists), not implementation details (extension_loaded, polyfill loaded). however, the loaded twice is not a real concern, why extension_loaded should not be used.

from mcrypt_compat.

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.