php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70504 DOMDocument::createAttribute add value as param
Submitted: 2015-09-15 14:36 UTC Modified: 2019-09-22 22:31 UTC
From: ricardo dot seromenho at gmail dot com Assigned: beberlei (profile)
Status: Wont fix Package: DOM XML related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
21 + 33 = ?
Subscribe to this entry?

 
 [2015-09-15 14:36 UTC] ricardo dot seromenho at gmail dot com
Description:
------------
Now if you want to use DOMDocument::createAttribute

$domDocument = new DOMDocument('1.0', "UTF-8");
$domElement = $domDocument->createElement('field','some random data');
$domAttribute = $domDocument->createAttribute('name');

// Value for the created attribute
$domAttribute->value = 'attributevalue';

// Don't forget to append it to the element
$domElement->appendChild($domAttribute);

// Append it to the document itself
$domDocument->appendChild($domElement);


What I am suggesting is because DOMDocument::createAttribute returns
a new instance of class DOMAttr. And the DOMAttr class contructor accepts as params the name and the value of the attribute, so I suggest that createAttribute also accepts value as a param

$domDocument = new DOMDocument('1.0', "UTF-8");
$domElement = $domDocument->createElement('field','some random data');

// Create and set value for the attribute
$domAttribute = $domDocument->createAttribute('name', 'attributevalue');

// Don't forget to append it to the element
$domElement->appendChild($domAttribute);

// Append it to the document itself
$domDocument->appendChild($domElement);


---
Because this is possible

$domDocument = new DOMDocument('1.0', "UTF-8");
$domElement = $domDocument->createElement('field','some random data');

// Create and set value for the attribute
// Using the DOMAttr directly
$domAttribute = new \DOMAttr('name', 'attributevalue');

// Don't forget to append it to the element
$domElement->appendChild($domAttribute);

// Append it to the document itself
$domDocument->appendChild($domElement);



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-15 19:50 UTC] requinix@php.net
DOM is an actual standard, not some thing PHP came up with, so it's not necessarily a good idea to make modifications to it.

Document::createAttribute(DOMString name) -> Attr
http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-1084891198

With that said, DOM 4 is looking to remove that method entirely so that may mean we have a bit more flexibility.
http://www.w3.org/TR/2015/WD-dom-20150618/#dom-document-createattribute
 [2019-09-22 22:31 UTC] beberlei@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: beberlei
 [2019-09-22 22:31 UTC] beberlei@php.net
Closing this as we want to stay as close as possible to the standard.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC