dslijian2015
dslijian2015
2013-01-24 14:27
浏览 79
已采纳

未定义的变量

I have defined the 2 variables, in contact and shirts. As you can see they are also in the li in header. Still i get the message that both of the variables are undefined.

I get this error message:

( ! ) SCREAM: Error suppression ignored for ( ! )

Notice: Undefined variable: section in C:\wamp\www\Test\shirts4mike\inc\header.php on line 17

Call Stack #TimeMemoryFunctionLocation 10.0003243592{main}( )..\index.php:0

20.0006246920 include( 'C:\wamp\www\Test\shirts4mike\inc\header.php' )..\index.php:3 ">

and the same for line 18.

shirts.php:

     <?php
            $pageTitle = "Mike's Full Catalog of Shirts";
            $section = "shirts";
            include('inc/header.php'); ?>

                    <div class="section page">
                            <h1>Mikes&rsquo;s Full Catalog of Shirts</h1>
                    </div>

            <?php include ('inc/footer.php'); ?>

contact.php:

<?php
    $pageTitle = "Contact Mike";
     $section = "contact";
     include('inc/header.php'); ?>

           <div class="section page">

           <h1>Contact</h1>

           </div>


<?php include ('inc/footer.php'); ?>

header.php:

<html>
        <head>
                <title> <?php echo $pageTitle ?></title>
                <link rel="stylesheet" href="css/style.css" type="text/css">
                <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,700" type="text/css">
                <link rel="shortcut icon" href="favicon.ico">
        </head>
        <body>

                <div class="header">

                        <div class="wrapper">

                                <h1 class="branding-title"><a href="./">Shirts 4 Mike</a></h1>

                                <ul class="nav">
                                        <li class="shirts <?php if ($section == "shirts"){ echo "on"; } ?>"><a href="shirts.php">Shirts</a></li>
                                        <li class="contact <?php if ($section == "contact"){ echo "on"; } ?>"><a href="contact.php">Contact</a></li>
                                        <li class="cart"><a href="#">Shopping Cart</a></li>
                                </ul>

                        </div>

                </div>

                <div id="content">
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douji8017
    douji8017 2013-01-24 15:28
    已采纳

    When you see SCREAM in a PHP error message like this, it is due to the following circumstances:

    1. You have PHP's xDebug extension installed.
    2. xDebug is configured to prevent error supression.
    3. Your PHP code is attempting to suppress an error message using the @ symbol or other error suppression mechanisms, and xDebug is overriding this.

    xDebug is a PHP extension designed to help with debugging PHP programs. It should generally not be installed on a production system; only on a development system.

    xDebug has a setting called "Scream" which is designed to prevent errors being suppressed. This is again intended for use in a development system. The developer may want errors to be supressed under normal circumstances, but while debugging it is useful to see those errors. So the scream setting overrides all of PHP's normal ways of hiding error messages. This is useful for debugging, but is a terrible thing to have on a production system.

    xDebug should never be installed on a public facing production server, so if that describes your system you should remove it, or ask for it to be removed. This could be as simple as modifying the PHP.ini file to remove the references to xDebug (although that will just disable the extension rather than un-installing it).

    If it is installed and you can't do anything about it, then you need to find a better web host that doesn't install development tools on production systems.


    Having said all of that, if you're getting the message that $section is undefined, then it does imply a bug in the code that needs to be fixed.

    The error is occurring in header.php, when it is included from index.php.

    You've shown us shirts.php and contact.php, both of which set $section correctly. You haven't shown us index.php, but I would guess that it includes header.php in the same way as the others, but doesn't set $section like the others do.

    You can therefore fix the bug by editing index.php so that it sets $section in the same way a the other pages do. Even if it just sets it to a blank string, that will be enough to fix the bug.

    I hope that helps.

    点赞 评论
  • dongqishou7471
    dongqishou7471 2013-01-24 15:35

    You're looking at the wrong files

    The stack trace indicates that two files were included to get to this particular error (in reverse order):

    • inc\header.php
    • index.php

    In the question, index.php isn't shown - but it is most likely that you have:

    <?php
    $pageTitle = "something";
    include('inc/header.php');
    

    i.e. the variables that are missing are not declared before they are used in the code that you are executing.

    SCREAM

    scream is an extension which makes it ignore use of the @ operator - i.e. somewhere in the code that is being executed, it is being used, it's generally held as bad practice to ignore errors. You can however turn scream off - which is appropriate for a production/live app, though of course the errors/warnings/notices should be addressed.

    点赞 评论

相关推荐