SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2004
    Location
    berlin
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dom xml and references

    hello everybody,

    i'm not completely clear with that dom stuff and i think the following question could solve the problem. if i use some dom or xpath statement and get a nodeList or a Node, e.g. with

    $actualNode = $dom->firstChild;

    do i always get a reference to that element and - more important - is this always conected to that document? i guess yes, but for some reason, i need some help. in this case it would mean, that i can modify $actualNode *anywhere* and i would always modify the real document; right?! even if i would continue like that:

    function test($node) // would i need a '&' here, to get this working as
    // described? i guess not...
    {
    // modify node here
    // no return
    }

    test($actualNode);
    // saveXML back (with changes?)

    what would be the difference to that one?

    $actualNode = & $dom->firstChild;

    thanks in advance,
    andi

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    since dom xml is a php4 extension, i presuppose that you are using php4 ?
    php4 per default assigns by value, not by reference. while this is fine for scalar types, it certainly acts counter-intuitive in regards to objects.
    as a general rule of thumb, you should allways assign by reference, when dealing with objects. eg :
    PHP Code:
    function takeByRef(&$someObject) {
    }
    // and
    $someObject =& new MyObject(); 
    functions that retun objects, should also do so by reference, eg :
    PHP Code:
    function & gimmeAnObject() {
        return new 
    MyObject();
    }
    $someObject =& gimmeAnObject(); 
    check the php manual for more explanation on references :
    http://www.php.net/references

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Ireland
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hm, what do you think for php5 then

  4. #4
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php5 defaults to assigns objects by reference. therefore you don't need any ampersands under php5.
    the regular php forum would probably be more approrpiate for this kind of discussion.

  5. #5
    SitePoint Member
    Join Date
    Oct 2004
    Location
    berlin
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, thanks for your answer - i'm using php5.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •