rakshazi / getsettrait Goto Github PK
View Code? Open in Web Editor NEWMagic getter/setter trait for any PHP class in one string of code.
Magic getter/setter trait for any PHP class in one string of code.
getSetTrait/src/GetSetTrait.php
Line 101 in 5a5cd0e
string
is not a valid type for type hinting until PHP 7
I have a use case where it would be useful to be able to test whether or not a property has been assigned. Being able to call a $dummy->hasFoo()
method that returns a boolean indicating whether the property has been set.
In our use case it would be desirable to fetch all assigned properties from the object in an array.
If in unit testing, try to mock classes using this trait with the Mockery library an error occurs:
ErrorException: Declaration of Mockery_2_Class_Name_Here::__call($method, $args) should be compatible with Class\Name\Here::__call($method = NULL, $params = Array)
The issue is that Mockery replaces the __call method of it's own, and the declaration of the parameters doesn't match. Mockery should probably take care to ensure it doesn't do that, but in this case I think getSetTrait is partially at fault.
The __call magic method is invoked when you attempt to call a method that doesn't exist, so the first param (the method name) will always be supplied. Likewise if the method was called with no params, the second parameter will be an empty array, so that will also always be supplied. Hence there's no value in declaring these as optional, and changing that fixes the issue with mocking as well.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.