check my amazon wishlist


CoreMedia vs. TYPO3

TIMTAB latest builds

stable:
v0.5.11 from TER
bug fix: commenting was possible although disabled for a post

unstable:
2006-04-15

what's new in unstable:
Ready for TYPO3 4.0.0. Trackback routines reorganized. Now Trackbacks will be sent only when the post is not hidden. Please test wether Trackbacks are working when writing post with tools like w.bloggar.

renner

Coding Night Wannabe an Apple? Robert Sebastian Session Robert

Archives

Categories

Buddies and others

del.icio.us links del.icio.us linkage




    Powered by Technorati



    Disclaimer

    I just brought the site back to life so that people can stop reminding me that it's down. Please note that probably most if not all content is outdated. I'll try to update stuff as soon as possible.

    best Ingo

    18
    May
    2007

    PHP5: fun with references


    Note to myself and anybody else using PHP5:

    Today I was working on an extension and trying to produce a rootline from a different tree. As this is not possible with standard HMENU objects I had to go the long way and code it myself.

      -2:<?php
    -1:
    0: $treeGetVars   
    t3lib_div::_GET('tx_somesecretextension_tree');
    1:
    $temp_sys_page = $GLOBALS['TSFE']->sys_page;
    2:
    $temp_tmpl     = $GLOBALS['TSFE']->tmpl;
    3:         
    4:
    $rootLine $temp_sys_page->getRootline($treeGetVars['subpage']);
    5: unset(
    $rootLine[0]);
    6:
    7:
    $temp_tmpl->rootLine array_reverse($rootLine);
    8:
    9:
    $menu t3lib_div::makeInstance('tslib_tmenu');
    10:
    $menu->parent_cObj $this->cObj;
    11:
    $menu->start($temp_tmpl$temp_sys_page$this->cObj->data['pages'], $conf1);
    12:
    $menu->makeMenu();
    13:
    $content $menu->writeMenu();
    14:
    15:
    ?>

    So I was trying to be carefull and not modify the global TSFE, instead copying them to a local variable. But right in that moment PHP5 had me! Myself asuming to be working with a local copy I was going nuts and wondering why it was destroying the output of itself and another menu from the same plugin.

    The problem:
    Have a look at lines 1 and 2! Nothing special, right? Well, remember it's PHP5 and thus it's working with references internally! Instead of working with a copy like I believed I was still working with the actual global instance... So when manipulating my local variable's rootline I was also modifying the global one ... *§$&"!%.

    The solution:
    Simply force PHP to give you a real copy by using clone:

       1: $temp_sys_page = clone $GLOBALS['TSFE']->sys_page;
    2:
    $temp_tmpl     = clone $GLOBALS['TSFE']->tmpl;

    Have fun with PHP5 - ehm for those TYPO3 5.0 guys out there also PHP6 ;-) - and references!

    comments

    No comments yet. Be the first to comment on this!

    Sorry, comments are closed for this post.