code/ViewableWrapper.php
public function obj($fieldName, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null)
    {
        $value = parent::obj($fieldName, $arguments, $forceReturnedObject, $cache, $cacheName);

        // if we're publishing and this variable is qualified, output php code instead
        if (
            $this->failover
            && $this->liveVars
            && isset($this->varName)
            && LivePubHelper::is_publishing()
            && $this->isLiveVar($fieldName)
        ) {
            $accessor = "get{$fieldName}";
            $php = '';

            // find out how we got the data
            if ($this->failover instanceof ArrayData) {
                $php = '$' . $this->varName . '["' . $fieldName . '"]';
            } elseif (is_callable(array($this->failover, $fieldName))) {
                // !@TODO respect arguments
                $php = '$' . $this->varName . '->' . $fieldName . '()';
            } elseif (is_callable(array($this->failover, $accessor))) {
                // !@TODO respect arguments
                $php = '$' . $this->varName . '->' . $accessor . '()';
            } elseif (isset($this->failover, $fieldName)) {
                $php = '$' . $this->varName . '->' . $fieldName;
            }
            
            // return the appropriate php
            if ($php) {
                if (is_object($value)) {
                    if ($value instanceof ViewableWrapper) {
                        LivePubHelper::$init_code[] = '<?php $' . $value->getVar() . ' = ' . $php . ' ?>';
                    }
                    // !@TODO: only other option is DataObjectSet - check that this is handled right
                } else {
                    $value = in_array($fieldName, $this->liveVarsUnescaped)
                        ? '<?php echo ' . $php . '; ?>'
                        : '<?php echo htmlentities(' . $php . '); ?>';
                    if ($forceReturnedObject) {
                        $value = new HTMLText($value);
                    }
                }
            }
        }
        
        return $value;
    }
public function obj($fieldName, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null)
    {
        $value = parent::obj($fieldName, $arguments, $forceReturnedObject, $cache, $cacheName);

        // if we're publishing and this variable is qualified, output php code instead
        if (
            $this->failover
            && $this->liveVars
            && isset($this->varName)
            && LivePubHelper::is_publishing()
            && $this->isLiveVar($fieldName)
        ) {
            $accessor = "get{$fieldName}";
            $php = '';

            // find out how we got the data
            if ($this->failover instanceof ArrayData) {
                $php = '$' . $this->varName . '["' . $fieldName . '"]';
            } elseif (is_callable(array($this->failover, $fieldName))) {
                // !@TODO respect arguments
                $php = '$' . $this->varName . '->' . $fieldName . '()';
            } elseif (is_callable(array($this->failover, $accessor))) {
                // !@TODO respect arguments
                $php = '$' . $this->varName . '->' . $accessor . '()';
            } elseif (isset($this->failover, $fieldName)) {
                $php = '$' . $this->varName . '->' . $fieldName;
            }
            
            // return the appropriate php
            if ($php) {
                if (is_object($value)) {
                    if ($value instanceof ViewableWrapper) {
                        LivePubHelper::$init_code[] = '<?php $' . $value->getVar() . ' = ' . $php . ' ?>';
                    }
                    // !@TODO: only other option is DataObjectSet - check that this is handled right
                } else {
                    $value = in_array($fieldName, $this->liveVarsUnescaped)
                        ? '<?php echo ' . $php . '; ?>'
                        : '<?php echo htmlentities(' . $php . '); ?>';
                    if ($forceReturnedObject) {
                        $value = new HTMLText($value);
                    }
                }
            }
        }
        
        return $value;
    }
If we're publishing, returns proper php