Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Missing the "length" property #32

shadowhand opened this Issue · 7 comments

2 participants


It would be really nice if QueryPath implemented the length property for matches. For example:

echo qp($doc, $path)->length;

As far as I can tell, there is no simple way to determine how many elements have been matched.


Like jQuery, we have a size() method.

I'm marking this as a feature request, though, because I think jQuery also has a length property.


Technically, the length property is the standard Javascript array count. jQuery returns an "array-like object" which has a length property.


So what do you think we should try to provide a length property? Or perhaps a length() method (which might be a little easier to manage)?


I think it should definitely be a property. The easiest way would be to have a __get magic method that aliases length to size(). Otherwise you'll have to update the property every time matches is modified, which could get redundant rather quickly.


Good idea on the magic method. That's probably the best way to go at this point.


Looks like setMatches() might be a good place to set an actual $length property. I think I'll look into testing that.


This will make it into QueryPath 2.1beta2

@sdboyer sdboyer referenced this issue from a commit in sdboyer/querypath
@technosophos Addressed bug in my implementation of :contains(), added contains-exa…

Previous versions of :contains() looked for an exact match in
PCDATA. Now, to match jQuery, we do a substring match. The new
:contains-exactly() pseudoclass performs the task formerly
handled by :contains(). Issue #32.
@sdboyer sdboyer referenced this issue from a commit in sdboyer/querypath
@technosophos Issue #32: Added a magic method for 'length'. 3b5339c
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.