Giter Club home page Giter Club logo

Comments (5)

samdark avatar samdark commented on July 28, 2024

One use case is objects validation via specifying path to the property i.e. owner.name to try calling $object->getOwner()->getName().

from arrays.

viktorprogger avatar viktorprogger commented on July 28, 2024

It's kind of black magic. Yii 3 usually avoids it.
IMHO ArrayHelper must not deal with object methods. It's not just an ability for user to shoot off his leg, it's a provocation.
In case of validation it's ok either to implement DataSet in the validatable object directly, or create a wrapper with this interface. But it is not ok to magically call object methods without a guarantee these methods don't change state or call some services like these:

class Test {
    private $prop = 1;

    public function getProp()
    {
        return $this->prop++;
    }
}
class Test2 {
    private $prop = null;

    public function getProp()
    {
        if ($this->prop === null) {
            $infrastructure = $this->httpService->deployInfrastructureFor($this);
            $this->prop = $this->infraRepository->save($infrastructure);
        }

        return $this->prop;
    }
}

from arrays.

wispoz avatar wispoz commented on July 28, 2024

It's kind of black magic. Yii 3 usually avoids it.
IMHO ArrayHelper must not deal with object methods. It's not just an ability for user to shoot off his leg, it's a provocation.
In case of validation it's ok either to implement DataSet in the validatable object directly, or create a wrapper with this interface. But it is not ok to magically call object methods without a guarantee these methods don't change state or call some services like these:

class Test {
    private $prop = 1;

    public function getProp()
    {
        return $this->prop++;
    }
}
class Test2 {
    private $prop = null;

    public function getProp()
    {
        if ($this->prop === null) {
            $infrastructure = $this->httpService->deployInfrastructureFor($this);
            $this->prop = $this->infraRepository->save($infrastructure);
        }

        return $this->prop;
    }
}
  1. Yes i agree with you, and i suggest remove from ArrayHelper ability to deal with objects and make separated package for this.
  2. Remove methods html* from ArrayHelper, because this methods dont deal with arrays. Maybe make HtmlHelper

from arrays.

viktorprogger avatar viktorprogger commented on July 28, 2024

I'm agree with you about html* methods, it's more about yiisoft/strings. But let's keep one issue for 1 theme :)

from arrays.

wispoz avatar wispoz commented on July 28, 2024

I'm agree with you about html* methods, it's more about yiisoft/strings. But let's keep one issue for 1 theme :)

Yes, you right!

from arrays.

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.