JSimpleXML deprecated

422 views
Skip to first unread message

Hannes Papenberg

unread,
Jan 3, 2010, 10:19:02 AM1/3/10
to Joomla! Framework Development
Hi folks,
in a discussion about 1.6, where we made a list of things to fix before
going beta, we decided to deprecate JSimpleXML in favour of PHPs built
in SimpleXML. Using SimpleXML is a performance improvement over
JSimpleXML and again its making the framework leaner. :-)

I have officially commited the change a few minutes ago and marked the
classes JSimpleXML and JSimpleXMLElement as deprecated. However, it is
still used in the core since currently none of the people with the
"official" developers hat on have the time to properly clean this up and
rewrite the code. A quick search came up with 15 matches where it is
used in a function in our framework. I would be very happy if someone
would take up this task and look into replacing the calls to
JFactory::getXMLParser('Simple') and subsequent function calls with the
correct classes and functions from SimpleXML. Unfortunately, they are
not 100% equal. As always: If you come up with a (working) patch, we
commit it to the trunk. :-) If you are willing to work on this, write a
quick response and open a tracker item in the 1.6 feature patch tracker:
http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemBrowse&tracker_id=8549

Thank you!

Hannes

Beat

unread,
Jan 3, 2010, 3:29:04 PM1/3/10
to Joomla! Framework Development

Hi Hannes,

Why don't you just do a:

class JSimpleXMLElement extends SimpleXML { }

It actually would allow you to fix some PHP SimpleXML bugs which are
in PHP < 5.2.4... unless Joomla 1.6 is PHP >= 5.2.4...

class JSimpleXMLElement extends SimpleXMLElement {
/**
* Get the name of the element.
* Warning: don't use getName() as it's broken up to php 5.2.3
included.
*
* @return string
*/
function name( ) {
if ( version_compare( phpversion(), '5.2.3', '>' ) ) {
return $this->getName();
} else {
return $this->aaa->getName(); // workaround php bug number 41867,
fixed in 5.2.4
}
}
}

It would allow to add some useful functions missing from the PHP
SimpleXML class as well.

Best Regards,
Beat
http://www.joomlapolis.com/

> quick response and open a tracker item in the 1.6 feature patch tracker:http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemBr...
>
> Thank you!
>
> Hannes

El KuKu

unread,
Jan 4, 2010, 2:38:31 PM1/4/10
to Joomla! Framework Development
Hello,
i like the idea of removing JSimpleXML in favor of SimpleXMLElement.

The quick search turned out the following 15 results:

installation/includes
aplication.php

libraries/joomla
application
helper.php (2X)
form
form.php
html
parameter.php
installer
helper.php
installer.php
librarymanifest.php
packagemanifest.php
adapters
file.php
library.php
package.php
plugin.php
language
help.php
language.php

As far as I can see, JForm (and it's fields and rules classes) needs
most attention (along with JParameter).

I would suggest a new factory method like loadXMLFile() which could be
like this:

/**
* Reads a XML file.
*
* @param string $path Full path and file name.
*
* @return mixed JSimpleXMLElement on success | false on error.
*/
public static function loadXMLFile($path)
{
if( ! file_exists($path)) {
return false;
}

jimport('joomla.utilities.simplexmlelement');

return simplexml_load_file($path, 'JSimpleXMLElement');
}//function

along with beats suggestion.

The first try can be seen here:
http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=19272

Regards,
Nikolai

On Jan 3, 3:29 pm, Beat <beat...@gmail.com> wrote:
> Hi Hannes,
>
> Why don't you just do a:
>
> class JSimpleXMLElement extends SimpleXML { }
>
> It actually would allow you to fix some PHP SimpleXML bugs which are
> in PHP < 5.2.4... unless Joomla 1.6 is PHP >= 5.2.4...
>
> class JSimpleXMLElement extends SimpleXMLElement  {
>         /**
>          * Get the name of the element.
>          * Warning: don't use getName() as it's broken up to php 5.2.3
> included.
>          *
>          * @return string
>          */
>         function name( ) {
>                 if ( version_compare( phpversion(), '5.2.3', '>' ) ) {
>                         return $this->getName();
>                 } else {
>                         return $this->aaa->getName();             // workaround php bug number 41867,
> fixed in 5.2.4
>                 }
>         }
>
> }
>
> It would allow to add some useful functions missing from the PHP
> SimpleXML class as well.
>
> Best Regards,

> Beathttp://www.joomlapolis.com/

Andrew Eddie

unread,
Jan 5, 2010, 12:25:07 AM1/5/10
to joomla-dev...@googlegroups.com
Should we consider, then, raising the minimum spec to PHP 5.2.4?

Regards,
Andrew Eddie
http://www.theartofjoomla.com - the art of becoming a Joomla developer


2010/1/4 Beat <bea...@gmail.com>:

> --
>
> You received this message because you are subscribed to the Google Groups "Joomla! Framework Development" group.
> To post to this group, send an email to joomla-dev...@googlegroups.com.
> To unsubscribe from this group, send email to joomla-dev-frame...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/joomla-dev-framework?hl=en-GB.
>
>
>

Sam Moffatt

unread,
Jan 5, 2010, 12:45:16 AM1/5/10
to joomla-dev-framework
Debian Lenny (their current stable) is on 5.2.6 so I wouldn't see an
issue with that.

Sam Moffatt
http://pasamio.id.au

Beat

unread,
Jan 5, 2010, 9:34:23 AM1/5/10
to Joomla! Framework Development
On Jan 5, 6:25 am, Andrew Eddie <mambob...@gmail.com> wrote:
> Should we consider, then, raising the minimum spec to PHP 5.2.4?

Hi Andrew,

To reply to your question: If you don't want to need to implement a
Joomla-specific class for SimpleXML for fixing a bug, 5.2.4+ would
make sense.
btw: I didn't see significant performance in extending
SimpleXMLElement, and it nicely extends the whole tree fine.

Setting minimum higher than 5.2.0 would also make sense for many other
bugs of PHP 5.2.0, 5.2.1 and up to 5.2.5 in particular. I've lately
also ran into a very wierd php memory-corruption bug which was
corrupting heavily referenced function parameters, and got fixed only
in 5.2.6.

One example of a heavy debug in CB on this PHP < 5.2.5 memory/
parameter-corruption bug here:
https://www.joomlapolis.com/component/option,com_joomlaboard/Itemid,38/func,view/id,118876/catid,88/limit,6/limitstart,30/

we have in CB a db function (method):

function & loadTrueObjects( $class = null, $key = "",
$additionalVars = array() ) { .... }

that was called with only 2 params, but the third didn't default to
array() in a heavily loaded config !!!!

So, if you want to avoid such very very weird bugs taking days to
debug, I strongly recommend setting PHP 5.2.6 as a sound minimum for
Joomla 1.6.

El KuKu

unread,
Jan 5, 2010, 3:08:52 PM1/5/10
to Joomla! Framework Development
Raising the minimum specs is always great from the coders point of
view.
+1 ;)

When using SimpleXMLElement a great amount of type casting is
required. Some people find this tedious so - extending the
SimpleXMLElement could make sense.

Example:

==Accessing attributes==

JSimpleXML
$xml->attributes('foo');

SimpleXMLElement
(string)$xml->attributes()->foo;

? JSimpleXMLElement
$xml->getAttribute('foo');

public function getAttribute($name)
{
return (string)$this->attributes()->$name;
}//function

==Accessing data==

JSimpleXML
$xml->foo->data();

SimpleXMLElement
(string)$xml->foo;

? JSimpleXMLElement
$xml->foo->data();

public function data()
{
return (string)$this;
}//function

In my patches I haven't implemented the first but the latter, just
because it required no changes to the existing code.

I have finished the form package (i think) and this afternoon (night)
I will look into the installer.

JParameter - what about this class ?

An argument to have a Joomla! (factory) function to load XML files
would also be that you could have JError to display parse and loading
errors.
see: http://www.php.net/manual/en/simplexml.examples-errors.php

Best regards,
Nikolai

On 5 Jan, 09:34, Beat <beat...@gmail.com> wrote:
> On Jan 5, 6:25 am, Andrew Eddie <mambob...@gmail.com> wrote:
>
> > Should we consider, then, raising the minimum spec to PHP 5.2.4?
>
> Hi Andrew,
>
> To reply to your question: If you don't want to need to implement a
> Joomla-specific class for SimpleXML for fixing a bug, 5.2.4+ would
> make sense.
> btw: I didn't see significant performance in extending
> SimpleXMLElement, and it nicely extends the whole tree fine.
>
> Setting minimum higher than 5.2.0 would also make sense for many other
> bugs of PHP 5.2.0, 5.2.1 and up to 5.2.5 in particular. I've lately
> also ran into a very wierd php memory-corruption bug which was
> corrupting heavily referenced function parameters, and got fixed only
> in 5.2.6.
>
> One example of a heavy debug in CB on this PHP < 5.2.5 memory/

> parameter-corruption bug here:https://www.joomlapolis.com/component/option,com_joomlaboard/Itemid,3...

El KuKu

unread,
Jan 7, 2010, 12:33:06 AM1/7/10
to Joomla! Framework Development
Hello,
a complete patch is ready waiting for a review
http://joomlacode.org/gf/download/trackeritem/19272/47128/AA_complete.patch

Best regards,
Nikolai

> quick response and open a tracker item in the 1.6 feature patch tracker:http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemBr...
>
> Thank you!
>
> Hannes

Hannes Papenberg

unread,
Jan 7, 2010, 4:11:34 AM1/7/10
to joomla-dev...@googlegroups.com
Hello Nikolai,
great patch, I like it, but could you do me three favours?
1. Please don't remove simplexml.php in your patch. We deprecated it,
but we wont remove it before 1.7 or 1.8.
2. Due to the same reason, the JFactory function to get a JSimpleXML
object should not be removed.
3. Can you recreate this patch against the current trunk? There have
been some modifications that create issues.

In the end, this patch is a great improvement. In a short test, it meant
a performance improvement of about 15-20% when using JForm. 30% with the
translation changes, 20% with this patch... If we keep it up, J! will
render before you even start the request. ;-)

Hannes

El KuKu

unread,
Jan 8, 2010, 12:13:56 AM1/8/10
to Joomla! Framework Development
Hi Hannes,
1+2 So we need a new name.
JNewClass extends SimpleXMLElement
Another option would be going without a wrapper class and use only the
core php functions. No compat and no error handling.
3. Shure. Just advise me about the naming / extending thing.

20% of speed improvement sounds amazing. I had no idea it could be so
significant.

Nikolai

On Jan 7, 4:11 am, Hannes Papenberg <hackwa...@googlemail.com> wrote:
> Hello Nikolai,
> great patch, I like it, but could you do me three favours?
> 1. Please don't remove simplexml.php in your patch. We deprecated it,
> but we wont remove it before 1.7 or 1.8.
> 2. Due to the same reason, the JFactory function to get a JSimpleXML
> object should not be removed.
> 3. Can you recreate this patch against the current trunk? There have
> been some modifications that create issues.
>
> In the end, this patch is a great improvement. In a short test, it meant
> a performance improvement of about 15-20% when using JForm. 30% with the
> translation changes, 20% with this patch... If we keep it up, J! will
> render before you even start the request. ;-)
>
> Hannes
>
> Am 07.01.2010 06:33, schrieb El KuKu:
>
> > Hello,
> > a complete patch is ready waiting for a review

> >http://joomlacode.org/gf/download/trackeritem/19272/47128/AA_complete...

Hannes Papenberg

unread,
Jan 8, 2010, 4:32:03 AM1/8/10
to joomla-dev...@googlegroups.com
Just name the compat/extending class JSimpleXMLElem. :-)

Hannes

Beat

unread,
Jan 8, 2010, 9:26:40 AM1/8/10
to Joomla! Framework Development
2 cents:

1) JSimpleXMLElem vs JSimpleXMLElement will create confusion.

2) why not do the real stuff: replace the existing JSimpleXMLElement
by the new one: JSimpleXMLElement has been written exactly with that
in mind... ;-) :

class JSimpleXMLElement extends SimpleXMLElement {
}

and not depreciate JSimpleXMLElement as the goal was to remake the old
functions ? :-)

Hannes Papenberg

unread,
Jan 8, 2010, 9:39:58 AM1/8/10
to joomla-dev...@googlegroups.com
Or do it like Beat said. :-)

El KuKu

unread,
Jan 8, 2010, 11:59:41 AM1/8/10
to Joomla! Framework Development
Confusion :~(
I completely agree with Beat. It's the same like his first post and -
what is done by my patch.

It's only that his point 2) interferes with your former point 1)

You would have two classes with the same name and the ability to load
them both.

Please correct me if I'm wrong...
Nikolai

Hannes Papenberg

unread,
Jan 8, 2010, 12:11:43 PM1/8/10
to joomla-dev...@googlegroups.com
Hi Nikolai,
your patch removed JSimpleXML, although it kept JSimpleXMLElement. Keep
JSimpleXML. The second problem is, that unfortunately your code has a
slightly different syntax than JSimpleXMLElement. If you can get around
that, I'm fine. :-)

Hannes

El KuKu

unread,
Jan 8, 2010, 7:06:44 PM1/8/10
to Joomla! Framework Development
Hi Hannes,
I feel we are moving in circles..

Just to clarify:
At the moment there a two classes:
JSimpleXML
AND
JSimpleXMLElement

So if you keep JSimpleXML you cannot remove or modify
JSimpleXMLElement.

The initial idea was to remove JSimpleXML and keep a modified version
of JSimpleXMLElement extending and so adopting the syntax of PHPs
SimpleXMLElement.

As for the syntax - well I thought that it was the point we were
talking about - changing the syntax to generic SimpleXML..

What to do ?
Nikolai

El KuKu

unread,
Jan 10, 2010, 8:55:56 PM1/10/10
to Joomla! Framework Development
Here comes the second version:
http://joomlacode.org/gf/download/trackeritem/19272/47256/AA_complete_V2.patch

The installer adapters may not work as expected... I did some testing
installing J! 1.5 style components and it seems OK so far..

Regards,
Nikolai

El KuKu

unread,
Jan 12, 2010, 11:41:46 PM1/12/10
to Joomla! Framework Development
Hello again ;)

I made some changes to the installer adapters and tested them with the
'alpha' packages I found in SVN in testing/branches/installer_samples,
some slight formatting as Hannes told me, and updated to rev. #14146.
http://joomlacode.org/gf/download/trackeritem/19272/47290/AA_complete_V3.patch

Regards,
Nikolai

On Jan 10, 8:55 pm, El KuKu <joo...@nik-it.de> wrote:
> Here comes the second version:http://joomlacode.org/gf/download/trackeritem/19272/47256/AA_complete...

Hannes Papenberg

unread,
Jan 13, 2010, 10:35:04 AM1/13/10
to joomla-dev...@googlegroups.com
Commited.

Christophe Demko

unread,
Jan 13, 2010, 3:26:52 PM1/13/10
to Joomla! Framework Development
Hi all,

since new SimpleXML, there is a problem for installing plugin (http://
joomlacode.org/gf/download/trackeritem/19018/47297/plg_mycategory.zip)
There are also some errors due to the addAttribute which can not
support add operation when the attribute already exist (see the
chdemko branch)

Ch.D

On 13 jan, 16:35, Hannes Papenberg <hackwa...@googlemail.com> wrote:
> Commited.
>
> Am 13.01.2010 05:41, schrieb El KuKu:
>
> > Hello again ;)
>
> > I made some changes to the installer adapters and tested them with the
> > 'alpha' packages I found in SVN in testing/branches/installer_samples,
> > some slight formatting as Hannes told me, and updated to rev. #14146.

> >http://joomlacode.org/gf/download/trackeritem/19272/47290/AA_complete...

El KuKu

unread,
Jan 14, 2010, 1:56:15 AM1/14/10
to Joomla! Framework Development
Hi Christophe,
I downloaded the plugin, tried to install, uninstall und update it and
- couldn't see a problem.

The addAttribute() method in SimpleXMLElement will throw a warning if
the attribute already exists. As this behavior is different to
JSimpleXML it might require some more changes.
You can test if the attribute exists - Try:
if($xml->foo->attributes()->bar)
{
$xml->foo->attributes()->bar = 'baz';

// Or you can add
$xml->foo->attributes()->bar = $xml->foo->attributes()->bar.'baz';

// But you can not
$xml->foo->attributes()->bar .= 'baz';
}
else
{
$xml->foo->addAttribute('bar', 'baz2');
}

If you could point me to the errors I would prepare another patch to
save you some work ;)

Regards,
Nikolai

Reply all
Reply to author
Forward
0 new messages