Comments (5)
One use case is objects validation via specifying path to the property i.e. owner.name
to try calling $object->getOwner()->getName()
.
from arrays.
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.
It's kind of black magic. Yii 3 usually avoids it.
IMHOArrayHelper
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 implementDataSet
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; } }
- Yes i agree with you, and i suggest remove from ArrayHelper ability to deal with objects and make separated package for this.
- Remove methods html* from ArrayHelper, because this methods dont deal with arrays. Maybe make HtmlHelper
from arrays.
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.
I'm agree with you about
html*
methods, it's more aboutyiisoft/strings
. But let's keep one issue for 1 theme :)
Yes, you right!
from arrays.
Related Issues (20)
- Unexpected default value HOT 1
- ArrayableTrait: toArray doesn't resolve array members when no specific fields/expand is provided
- ArrayHelper::getObjectVars() description seems to be out of date HOT 2
- PHP 8 compatibility with \ArrayAccess
- Adjust input and output for `ArrayHelper::parsePath()` HOT 1
- How to create an array of strings in c language?
- Improve performance of getValueByPath() HOT 4
- Fix tests HOT 2
- Get array value by matcher HOT 1
- Extend the functionality of setValue HOT 3
- update irc link
- update src folder link
- Remove scrutinizer
- Psalm 5.23.1
- Increase MSI to 100
- Remove ArrayHelper::isTraversable
- Problem with support float as keys HOT 2
- ArrayHelper::multisort: remove support use \Closure with return multiple keys HOT 2
- Why methods like map expect array in first parameter instead of iterable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arrays.