Git Product home page Git Product logo

Comments (4)

marcovtwout avatar marcovtwout commented on July 17, 2024 1

Similar to #4516

from yii.

marcovtwout avatar marcovtwout commented on July 17, 2024 1

Fixed by #4519

from yii.

aztechowski avatar aztechowski commented on July 17, 2024

I've build an workaround (written in PHP 8.2 style), which can be adopted here.
Instead of

if(version_compare(PHP_VERSION,'8.0','>=')) {
    $isArray=$param->getType() && $param->getType()->getName()==='array';
} else {
  $isArray = $param->isArray();
}

I'm using following code

    //repleced by
    $isArray = $this->isParameterAnArray($param);
  
    //check whenever given parameter is an array, or not. Supports complex types (intersections, unions) from PHP 8 and above
    private function isParameterAnArray($param): bool
    {
        if (PHP_VERSION_ID < 80000) {
            return $param->isArray();
        }
        foreach ($this->getAllTypes($param) as $complexType) {
            if ($complexType && $complexType->getName() === 'array') {
                return true;
            }
        }
        return false;
    }

    //Get all available types. In case an Intersection (PHP >= 8.1) or Union Type (PHP > 8.0) is used, then give all defined types 
    private function getAllTypes($param): array
    {
        if ((PHP_VERSION_ID >= 81000) && $param->getType() instanceof ReflectionIntersectionType) {
            return $param->getType()->getTypes();
        }
        if ($param->getType() instanceof ReflectionUnionType) {
            return $param->getType()->getTypes();
        }
        return [$param->getType()];
    }

from yii.

aztechowski avatar aztechowski commented on July 17, 2024

Yep, it can be combined and solved together.

from yii.

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.