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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ricardo dot seromenho at gmail dot com
New email:
PHP Version: OS:

 

 [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: Wed Apr 24 17:01:30 2024 UTC