Comments (9)
Why? If you need to remove the content you can send an empty string as value.
from fluentdom.
Why what? It's about making it compatible with jQuery API.
Consider the following example:
$dom->html($w)->attr('placeholser',$x)->$attr('maxlength',$y)->$att('title',$t);
If any of $w,$t, .. variables is set to null the corresponding method will act as a getter, the chain will break and an exception will be thrown. This is not the case in jQuery api.
from fluentdom.
You can always cast the variables.
$dom->html((string)$w)->attr('placeholder',(string)$x)...
PHP functions usually make no difference between NULL and undefined. NULL is for optional parameters (type hints, but internal functions, too).
In your example you provide the arguments. See this example:
function dump() {
var_dump(func_get_args());
}
dump($a, $b);
array(2) {
[0]=>
NULL
[1]=>
NULL
}
from fluentdom.
You can easily solve that fundamentally and there is no need to add a (string)
everywhere.
function attr()
{
if (count(func_get_args()) < 2) {
return 'I am a getter!';
};
return 'I am a setter!!';
}
echo attr('type').PHP_EOL;
echo attr('type',null).PHP_EOL;
echo attr('type','foo');
I am a getter!
I am a setter!!
I am a setter!!
from fluentdom.
Yes, but even an undefined variable like in my example is treated as NULL. I will think about it, but I am a little afraid how much code (that uses FD) would break.
from fluentdom.
I don't know what you are trying to show by that example, how your example is related to this issue.. May you please provide an example of breaking code?
from fluentdom.
Some source that wraps or extends the current methods. It would expect the current behavior. If a method extends FluentDOM:attr() and calls the parent method expecting the current behavior it will break.
from fluentdom.
Variadics allow for a cleaner implementation of optional arguments (then func_get_args()) and even for generic wrapper functions:
function attr($name, ...$arguments) {
var_dump($arguments);
}
function attributes($name, ...$arguments) {
attr($name, ...$arguments);
}
attributes('one');
attributes('two', '21');
from fluentdom.
Well done. Thanks.
from fluentdom.
Related Issues (20)
- XMLWriter::collapse()
- Creator forgets namespace
- Allow to attach an exting stream to XMLReader HOT 1
- Bug: is() using CSS selector behaves like has() HOT 5
- Load an HTML fragment from an HTML5 source HOT 2
- Update MutationMacro according DOM 4.1
- Add ParentNode::$childElementCount
- Loading HTML5 fragment bug HOT 1
- Workaround for namespace definition removal
- HJson Loader
- Json5 loader
- Improve documentation for CSS selectors HOT 1
- preserveWhitespace in Libxml-Loader HOT 3
- Please support unwrap() HOT 4
- How to Iterate? HOT 2
- XDM Loader/Serializer
- What is the proper way to check for a missing file HOT 2
- What is the correct way to replace elements in a foreach? HOT 1
- PHP 8 support HOT 2
- Support PHP 8.1 better HOT 3
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 fluentdom.