Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 7 of 7

Thread: echo " "; fixes evaluation error

  1. #1

    echo " "; fixes evaluation error

    For some reason, I have an if statement that is evaluating incorrectly. Wierd thing is, if I put an echo " "; or a die (" "); anywhere in the script, it evaluates correctly and the script works perfectly. Does anybody know why the heck this is? Thanks
    [swf="http://www.captainclyde.net/temp/sig.swf height=60 width=300"][/swf]

  2. #2
    can you post an example?

  3. #3
    This is the script that is experiencing the problems. I've never seen this happen before.


    PHP Code:
    <?php

    // Mod Index Page
    // Written by John French
    // mod_index.php
    //
    // Primary index page for mod_user

    // Define the security control variable, IN_MOD.
    define("IN_MOD"1);

    //
    // Include the common includes
    // This include initializes the following objects
    //
    // $db = the database abstraction objct
    // $error = the error reporting object
    // $validator = the validation object
    //
    require_once "../mod_shared/mod_common.inc.php";

    //
    // include the layout of the site's pages
    //
    require_once "mod_page_params.inc.php";


    //--------------------------------------------Begin processing the page--------------------------------

    //
    // First, we process the variables sent to the page via the rewritten URL.
    // They come in the form www.site.com/page_var/variables (delimited by / )
    //
    if(isset($_GET['page']) && !empty($_GET['page']))
    {
        if(!
    $v_page $validator->validate_alphanumeric($_GET['page']))
        {
            
    // If page name is invalid, die with a 404
            
    $error->die_report("page_not_found"__LINE____FILE__);
        }
    }
    else
    {
        
    $v_page "index";
    }



    //
    // Now we process the variables sent with the URL
    //
    $_ARGS = array();

    if(isset(
    $_GET['args']) && !empty($_GET['args']))
    {
        
    // trim the annoying slash off of the end of the string
        
    $query_str rtrim($_GET['args'], "/");
        
        
    // break the query into variables stored into an array
        
    $_ARGS explode("/"$query_str);
    }
                            
    // check to see if our $v_page is in the site page array.  if it's not, then we check the mod page arr
    if(array_key_exists($v_page$site_page_arr))
    {
        
    $page_specs_arr $site_page_arr[$v_page];

    else if (
    array_key_exists($v_page$mod_page_arr))
    {
        
    $page_specs_arr $mod_page_arr[$v_page];

    else
    {
        
    $error->die_report("page_not_found"__LINE____FILE__);
    }

    //static
    if($page_specs_arr[0] == 0)
    {

        
    $template->set_template($page_specs_arr[1]);
        
        if(!
    $xhtml_main $template->parse_template())
        {
                    
    // if you put an echo " "; here, this conditional will evaluate correctly.  If not, it evaluates to true.
            
    $error->die_report("template_failed"__LINE____FILE__);
        }
        

    else
    {
        
    // dynamic page compiles and returns xhtml
        
    $page_inc $page_specs_arr[1];
        
    $xhtml_main = include($page_inc);
    }


    // 
    // Check to see if the page we are loading requires a 
    // template other than the default
    //


    if(isset($page_specs_arr[2]) && file_exists($page_specs_arr[2]))
    {
        
    // if key exists, set the xhtml_template to it's value
        
    $xhtml_template $page_specs_arr[2];
    }
    else
    {  
        
    // Use the main template
        
    $xhtml_template "../site_templates/xhtml_main.htm";
    }


    //
    //----------------------------------------------Site-specific Includes (editable)------------------------------------------
    //  Some sites will requre multiple script includes for various bits of dynamic content in other parts of
    //  the page that aren't the main body generated by the include script.
    //---------------------------------------------------------------------------------------------------------------


    //
    // Include pages that appear on the site that aren't the main content
    //

    // Include the upcoming shows script
    $xhtml_nav_2 "Upcoming Show: Sat Mar 22 11:00 PM Headhunter's"//include("mod_nextshow.php");

    // Include the photos script
    $xhtml_main_2 "View Photo"//include("mod_viewphoto.php");

    // Include the separate photo thumbnail script
    $xhtml_sub_2 "Thumbnails"//include("mod_viewthumbs.php");

    // Include the banner viewing script
    $xhtml_sub_1 = include("mod_userlogin.php");

    // Define the template variables and what they will be replaced by
    $xhtml_main_replacements = array(
                                        
    "{xhtml_head_1}"    => $xhtml_head_1,
                                        
    "{xhtml_nav_2}"        => $xhtml_nav_2,
                                        
    "{xhtml_sub_1}"        => $xhtml_sub_1,
                                        
    "{xhtml_sub_2}"        => $xhtml_sub_2,
                                        
    "{xhtml_main}"        => $xhtml_main,
                                        
    "{xhtml_main_2}"    => $xhtml_main_2
                                    
    );


    //---------------------------------------------- End site-specific includes-----------------------------------


    // ---------------------------------------------- Begin template formatting-----------------------------------
    //
    //
    $template->set_template($xhtml_template);

    if(!
    $xhtml_output $template->parse_template($xhtml_main_replacements))
    {    
        
    // Since this is the main template formatter, we can't generate a formatted error_doc
        // Therefore, we must DIE
        
    die("Primary template engine failure.<br /><b>Line: </b>" __LINE__ "<br /><b>File: </b>" __FILE__);
    }

    // Template successfully parsed.  Output valid XHTML.

    echo $xhtml_output;

    ?>
    [swf="http://www.captainclyde.net/temp/sig.swf height=60 width=300"][/swf]

  4. #4
    Which part of that do you think evaluates incorrectly?

    Generally speaking, anything 'fixed' by an 'echo' or 'die' was broken in the first place. Fix the heart of the problem, the workaround using echo or die is just hiding something (probably by sending output before the error generates a header() call).

  5. #5
    Quote Originally Posted by JustJeff
    Which part of that do you think evaluates incorrectly?

    Generally speaking, anything 'fixed' by an 'echo' or 'die' was broken in the first place. Fix the heart of the problem, the workaround using echo or die is just hiding something (probably by sending output before the error generates a header() call).
    I didn't put it in there to fix a problem. Initially, I was using the dieto try to debug the script. When I put it in there, the script executed fine AND completely ignored the die(). The part that is evaluating incorrectly is

    PHP Code:
    else
    {
        die(
    "shoud be dying here");
        
    $error->die_report("page_not_found"__LINE____FILE__);

    I've thoroughly investigated all of my scripts. No errors.
    [swf="http://www.captainclyde.net/temp/sig.swf height=60 width=300"][/swf]

  6. #6
    There's no way the die() is changing the way the if() {} elseif() {} else is evaluating - it's hiding something.

    If it were me, I'd be using print_r() to show all of those variables, because something isn't happening the way you expect.

  7. #7
    Quote Originally Posted by JustJeff
    There's no way the die() is changing the way the if() {} elseif() {} else is evaluating - it's hiding something.

    If it were me, I'd be using print_r() to show all of those variables, because something isn't happening the way you expect.

    I absolutely agree, I was just looking for a place to start in the process of debugging. I never entertained the idea of leaving the echo or die() in there as a hack. I'll try some stuff with print_r and see where it gets me. Thanks

    John
    [swf="http://www.captainclyde.net/temp/sig.swf height=60 width=300"][/swf]

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012