Req #70504 [Opn->Wfx]: DOMDocument::createAttribute add value as param

From: Date: Sun, 22 Sep 2019 22:31:36 +0000
Subject: Req #70504 [Opn->Wfx]: DOMDocument::createAttribute add value as param
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222876@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70504&edit=1

 ID:                 70504
 Updated by:         beberlei@php.net
 Reported by:        ricardo dot seromenho at gmail dot com
 Summary:            DOMDocument::createAttribute add value as param
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            DOM XML related
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        beberlei
 Block user comment: N
 Private report:     N

 New Comment:

Closing this as we want to stay as close as possible to the standard.


Previous Comments:
------------------------------------------------------------------------
[2015-09-15 19:50:44] 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

------------------------------------------------------------------------
[2015-09-15 14:36:03] 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);




------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=70504&edit=1


Thread (3 messages)

« previous php.bugs (#222876) next »