php method chaining not backward compatible

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jk8tow
Forum Newbie
Posts: 2
Joined: Fri Oct 16, 2009 8:04 pm

php method chaining not backward compatible

Post by jk8tow »

I'm new to php so please forgive me if this is elementary... I have a Wordpress plugin that a friend wrote with php 5. The plugin won't work on the server of the site I'm working on because the host is running php 4.4 (and is NOT going to upgrade). His plugin breaks during this part of the script: (the lines of method chaining)

Code: Select all

 
    function xml_flash_slideshow() {
        // check if there is anything posted    
        if(isset($_POST['save_changes'])) {         
            updateXmlFile();
        } else if(isset($_POST['reorder']) == 'true') {         
            updateXmlFile();
        } else { 
            // load xml file
            $settings_doc = new DOMDocument();
            $settings_doc -> load(ABSPATH.'wp-content/plugins/xml flash slideshow/xml/settings.xml');
            // get settings from file
            $width          = $settings_doc -> getElementsByTagName("width")            -> item(0) -> nodeValue;
            $height             = $settings_doc -> getElementsByTagName("height")           -> item(0)  -> nodeValue;
            $border_width       = $settings_doc -> getElementsByTagName("border_width")     -> item(0)  -> nodeValue;
            $border_radius      = $settings_doc -> getElementsByTagName("border_radius")            -> item(0)  -> nodeValue;
            $border_top_color   = $settings_doc -> getElementsByTagName("border_top_color") -> item(0)  -> nodeValue;
            $border_btm_color   = $settings_doc -> getElementsByTagName("border_btm_color") -> item(0)  -> nodeValue;
            $border_dropshadow  = $settings_doc -> getElementsByTagName("border_dropshadow")-> item(0)  -> nodeValue;
            $img_dot_color      = $settings_doc -> getElementsByTagName("img_dot_color")    -> item(0)  -> nodeValue;
            $images             = $settings_doc -> getElementsByTagName("image");
            foreach ($images as $image) {
                $paths      = $image -> getElementsByTagName( "path" );
                $path_obj   = $paths -> item(0) -> nodeValue;
                $links      = $image -> getElementsByTagName( "link" );
                $link_obj   = $links -> item(0) -> nodeValue;
                $path[]     = $path_obj;
                $link[]     = $link_obj;
            }
        }
 
How would something like this have been done in php 4? I thought I could just capture the same elements in an array and call them individually to place them into the respective vars... like I said, I'm a newb to php so I could be way off in my logic and syntax. Thanks for your help.

I forgot to mention... this is the error php is generating:
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in xml flash slideshow.php on line 30

line 30 in the file is : $width = $settings_doc -> getElementsByTagName("width") -> item(0) -> nodeValue;

... just in case I'm wrong about the error being from method chaining. Thanks again.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php method chaining not backward compatible

Post by requinix »

Code: Select all

$width = $settings_doc -> getElementsByTagName("width") -> item(0) -> nodeValue;
In PHP 4 you can't use -> on the result of a function. You'll have to break it apart using temporary variables.

Code: Select all

$temp = $settings_doc->getElementsByTagName("width");
$temp = $temp->item(0);
$width = $temp->nodeValue;
And let me go on the record: the host is stupid for not being willing to upgrade.
jk8tow
Forum Newbie
Posts: 2
Joined: Fri Oct 16, 2009 8:04 pm

Re: php method chaining not backward compatible

Post by jk8tow »

Thanks... I broke it apart once but was still getting errors... could just be syntax. I'll try it again, thanks for your help.

And I completely agree with you about the host not upgrading. Frustrating.
Post Reply