php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41258 setAttributeNS has inconsistent behaviour when raising exceptions
Submitted: 2007-05-02 08:55 UTC Modified: 2007-05-02 14:50 UTC
From: daniel dot oconnor at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.1 OS:
Private report: No CVE-ID: None
 [2007-05-02 08:55 UTC] daniel dot oconnor at gmail dot com
Description:
------------
Inconsistent behaviour when raising exceptions. No exception is raised until line 10

Reproduce code:
---------------
<?php
$d = new DOMDocument();
$example = $d->createElementNS('http://foo.com','example');
$example->setAttributeNS('http://bar.com', 'bar:bar',"value");
$example->setAttributeNS('http://bar.com', 'monkey',"value");

$d = new DOMDocument();
$example = $d->createElementNS('http://foo.com','example');
$example->setAttributeNS('http://fish.com', 'bar:bar',"value");
$example->setAttributeNS('http://bar.com', 'monkey',"value");

Expected result:
----------------
 1. An exception raised on the second setAttributeNS (line 4)
 2. A more meaningful error than 'Namespace Error' - "No namespace prefix found for <http://fish.com>"

Actual result:
--------------
An exception on line 10

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-02 12:54 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

Line 4 is fine as namespace URI with an associated prefix already exists (it was created when from line 3). The prefix gets attached to the attribute. Error messages are not a bug, but feel free to open a feature request for more verbose messages though.
 [2007-05-02 14:50 UTC] daniel dot oconnor at gmail dot com
This is not a functionality bug, but a usability one.

Please see http://clockwerx.blogspot.com/2007/05/bogus-this.html for more detail - it expands on some of the real world use problems related to the behavior exhibited here. Take it with a grain of salt, because I've been fighting this code all day and am more than a little cranky.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 28 23:01:30 2024 UTC