You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
0 is the default root node ID (see https://github.com/BlueM/Tree/blob/master/src/Tree.php#L29). So $sut->getNodeById(0) returns the root node, and this is the expected behaviour. Getting the root node for '0' and false can be explained thru implicit type coercion – which could of course be prevented using strict types, but these are edge cases, and I guess in the vast majority of cases, this would be rather counterproductive.
On the other hand, the library is inconsistent – there is a $rootId, but the node with that ID is none of the nodes returned by getRootNodes(), which is a surprising behavior. Basically, the mere existence of a root ID is an implementation detail, and probably it would be better if there was none, as it doesn’t have any practical use. I’ll look into this.
\BlueM\Tree::getNodeById() returns non-existent nodes:
Expected behavior: when an id does not exist, an \InvalidArgumentException should be thrown.
Details
There seems to be a problem with
0 (int)
,'0' (string)
andfalse (bool)
:Result:
The text was updated successfully, but these errors were encountered: