Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2011
    Posts
    56
    Thanks
    5
    Thanked 2 Times in 2 Posts

    includes out side of two functions

    My functions only work when I include accompanying php files inside of the functions on the same page. Is there a global function or something in the manual that I'm missing here?

    This works:

    PHP Code:

    // First Function
    function one() { 

    include (
    TEMPLATEPATH 'filea.php'); 
    include (
    TEMPLATEPATH 'fileb.php');
    include (
    TEMPLATEPATH 'filec.php');

    if (
    arguments) ){ 
            echo 
    'something';}

    elseif (
    arguments) ){ 
            echo 
    'something';}

    else (
    arguments) ){ 
            echo 
    'something';}




    // Second Function
    function two() { 

    include (
    TEMPLATEPATH 'filea.php'); 
    include (
    TEMPLATEPATH 'fileb.php');
    include (
    TEMPLATEPATH 'filec.php');

    if (
    arguments) ){ 
            echo 
    'something';}

    elseif (
    arguments) ){ 
            echo 
    'something';}

    else (
    arguments) ){ 
            echo 
    'something';}


    Doesn't work:

    PHP Code:

    include (TEMPLATEPATH 'filea.php'); 
    include (
    TEMPLATEPATH 'fileb.php');
    include (
    TEMPLATEPATH 'filec.php');

    // First Function
    function one() { 

    if (
    arguments) ){ 
            echo 
    'something';}

    elseif (
    arguments) ){ 
            echo 
    'something';}

    else (
    arguments) ){ 
            echo 
    'something';}




    // Second Function
    function two() { 

    if (
    arguments) ){ 
            echo 
    'something';}

    elseif (
    arguments) ){ 
            echo 
    'something';}

    else (
    arguments) ){ 
            echo 
    'something';}


    I use this in a custom wordpress theme, tried excluding the TEMPLATEPATH call and still no luck. Thanks for looking!
    Last edited by neptune1; 04-07-2014 at 02:31 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Simple scope issue. Anything declared in a scope cannot be used outside of the scope; you cannot use a variable declared outside of a function in a function or vice versa.
    PHP has a global method which can be retrieved using the global keyword or from the $GLOBALS array; however, a better way is to provide an parameter list to the function signature and use a switch/if/elseif branch to evaluate instead.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New Coder
    Join Date
    Feb 2011
    Posts
    56
    Thanks
    5
    Thanked 2 Times in 2 Posts
    thanks!


  •  

    Posting Permissions

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