php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36538 Different integer values for XmlReader node types
Submitted: 2006-02-26 22:26 UTC Modified: 2006-02-27 15:04 UTC
From: paul at stunning-stuff dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.1.2 OS: Win XP Pro SP2
Private report: No CVE-ID: None
 [2006-02-26 22:26 UTC] paul at stunning-stuff dot com
Description:
------------
Hi,

I was fooling around with the XmlReader class and I just thought to myself... Why are the values of the node type constants 1 to 17. Why not use 1, 2, 4, 8, 16, 32, 64, etc.
This way you could use bitwise operators:

while ($xmlReader->read())
{
  switch ($xmlReader->nodeType)
  {
    case XmlReader::ELEMENT:
      // Do stuff.
      break;
    case XmlReader::END_ELEMENT:
      // Do stuff.
      break;
    case (XmlReader::TEXT | XmlReader::CDATA):
      // Do stuff for text nodes and cdata nodes.
      break;
  }
}

This would improve readability of the code in many cases. This type of change could be done to other constants used in other classes/functions as well to improve their usability (can't think of any at the moment though).

Also, this type of change shouldn't cause anyone's (decent) code to break.

Thanks,

Paul


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-27 15:04 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

They are numbered that way as that is how they are defined in the underlying library as well as the fact that XMLReader is based on the .NET implementation (where the types are numbered the same)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 26 00:00:03 2025 UTC