wolferhua / phpquery

Automatically exported from code.google.com/p/phpquery
0 stars 0 forks source link

Can't chaining using attr method with a null value #47

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. using <php>$myPhpQuery->attr('attributeName',null)->end();</php>
2.
3.

What is the expected output? What do you see instead?
I should chaining other method after end() but can't, instead of that it
display me that <error>Fatal error: Call to a member function end() on a
non-object</error>

What version of the product are you using? On what operating system?
r167

Please provide any additional information below.
I really understand why it do that, cause using a null second argument make
the function return te attribute "attributeName" but sometimes I include
some value from BDD and actually I have to test it if NULL or not before
insert it :(.

Original issue reported on code.google.com by nicolas....@gmail.com on 2 Oct 2008 at 7:55

GoogleCodeExporter commented 9 years ago
Personally i dont think setting null and preserving chain is correct behaviuor. 
Such
thing should be done thought removeAttr($name) or at least attr($name, "").

Thats simply because there is no (straightforward) way to determine what do you
expect when second param is null (it should be by default something which 
simulates
null, but its not null).

But i can be wrong, does jQuery allows that ?

Original comment by tobiasz....@gmail.com on 2 Oct 2008 at 9:00

GoogleCodeExporter commented 9 years ago
I think jQuery allows chaining in such a case. It does not chain on the 
attribute 
but on the element from which the attribut has been deleted / remove or in this 
case 
set to null.

But there is no setting to null with jQuery. Just an Idea: Maybe setting an 
attribute value to null should throw an exception for the sake of clarify.

Original comment by artn...@gmail.com on 5 Oct 2008 at 10:04

GoogleCodeExporter commented 9 years ago
Test case :
<js>$('div#contenu_actualite').attr('id',null).find('div.bloc_arrondi_haut').att
r('class');</js>
display : "bloc_arrondi_haut" so chaining works

<js>$('div#contenu_actualite').attr('id',undefined).find('div.bloc_arrondi_haut'
).attr('class');</js>
get an error, so chaining doesn't work

Original comment by nicolas....@gmail.com on 6 Oct 2008 at 10:23

GoogleCodeExporter commented 9 years ago
A little "hack" to get chaining work with null value is :
<php>
$myValue = null;

echo $myPhpQuery->find('#myId)->attr('myAttr',''.$myValue)->end()->html();
</php>

And it's working ;).

Original comment by nicolas....@gmail.com on 13 Oct 2008 at 1:58

GoogleCodeExporter commented 9 years ago
As PHP doesnt support 'undefined' type, 'null' is used as equivalent.
In jQuery following code:
.attr('id',null)
will result in id='null'
In phpQuery it can be easly achived by:
->attr('id', 'null')
with same result.

Original comment by tobiasz....@gmail.com on 18 Oct 2008 at 9:00