Jump to content

call to undefine function


Recommended Posts

Hi, when you have a call to undefined function error, that usually means either you misspelled the function name or the function file isn't attached to the page, right?  Can someone help me understand why I'm getting that error?  The function names are spelled the same and the function file is attached so I'm not understanding what 's wrong. 

<php
require_once('functions.php');
?>  
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Untitled Document</title>
<meta name="keywords" content="">
<meta name="description" content="">
<link rel = "stylesheet" href = "Bixler.css">
<style type="text/css">

</style>
</head>
<body>
<?php headerInfo();?>
<article>

</article>
<aside>

</aside>
<footer>
	<div id="contactInfo">
    	Bixler Insurance <br/>
	    1043 South 13th St. <br />
	    Decatur, IN 46733<br />
		Phone: (260)-724-3438
    </div>
    <div id="eocialMedia">
		social media icons
    </div>    
    <div id="servicesList">
    	list of services
    </div>
</footer>
</body>
</html>

<?php
function headerInfo() {
<<<HEREDOC
<header>
<nav>
	<ul>
    	<li><a href="#">Home</a></li>
    	<li><a href="#">About Us</a>
        	<ul>
       	    	<li><a href="#">Agents</a></li>
		    	<li><a href="#">Locations</a></li>                
			</ul>
      <li><!--end of about us menu list -->   
    	<li><a href="#">Services</a></li>               
    	<li><a href="services.php" tabindex="3" accesskey="S">Services</a></li>
    	<li><a href="quote.php" tabindex="4" accesskey="Q">Get A Quote</a></li>
    	<li><a href="contact.php" tabindex="5" accesskey="C">Contact</a></li>
   </ul>
</nav>  
	<figure id="logo">
   		<img src="assets/bixlerlogo.png" width="304" height="88" alt=""/>
    </figure>
    <h3>Service Beyond The Contract </h3>
</header>
HEREDOC;
/*end of headerInfo function */

/*start of footerInfo function */
function footerInfo() {
<<<HEREDOC
<footer>
	<div id="contactInfo">
    	Bixler Insurance <br/>
	    1043 South 13th St. <br />
	    Decatur, IN 46733<br />
 		Phone: (260)-724-3438
     </div>
     <div id="eocialMedia">
		social media icons
     </div>
     <div id="servicesList">
    	list of services
     </div>
</footer>
}
HEREDOC;

/*end of footerInfo function */
?>
Link to comment
Share on other sites

You should be getting a parsing error from the look of it, because your functions are not ended properly.

 

 

function_name() {
   //code
}
In both cases your HEREDOC closing is outside of the end of the function.

 

Furthermore HEREDOCS work like so:

 

$var = <<<HEREDOC
....
HEREDOC;
echo $var;
Link to comment
Share on other sites

I think I see what you mean, but I'm still getting a call to undefined function headerInfo()

function headerInfo() {
<<<HEREDOC
<header>
<nav>
	<ul>
    	<li><a href="#">Home</a></li>
    	<li><a href="#">About Us</a>
        	<ul>
       	    	<li><a href="#">Agents</a></li>
		    	<li><a href="#">Locations</a></li>                
			</ul>
      <li><!--end of about us menu list -->   
    	<li><a href="#">Services</a></li>               
    	<li><a href="services.php" tabindex="3" accesskey="S">Services</a></li>
    	<li><a href="quote.php" tabindex="4" accesskey="Q">Get A Quote</a></li>
    	<li><a href="contact.php" tabindex="5" accesskey="C">Contact</a></li>
   </ul>
</nav>  
	<figure id="logo">
   		<img src="assets/bixlerlogo.png" width="304" height="88" alt=""/>
    </figure>
    <h3>Service Beyond The Contract </h3>
</header>
HEREDOC;
}
Edited by MediaSvcsUnlimited
Link to comment
Share on other sites

The values are correct. display_errors must be 1, error_reporting must be E_ALL.

 

E_ALL can optionally be replaced with -1, but this is an obsolete workaround for early PHP versions where E_ALL didn't actually mean “all errors”. Since PHP 5.4, E_ALL does exactly what it says.

Link to comment
Share on other sites

You need echo or return. Such as:

<?php function headerInfo(){ 
return <<<HEREDOC
...
HEREDOC;
} ?>
...
<?php echo headerInfo(); ?>
or

 

<?php function headerInfo(){ 
echo <<<HEREDOC
...
HEREDOC;
} ?>
...
<?php headerInfo(); ?>
Your posts up until now included neither.

 

Note that you don't need to use a HEREDOC at all. You can just exit PHP mode, dump your HTML, then re-enter PHP mode and end the function. I personally find that to be cleaner when dealing with large chunks of HTML, and it sometimes works better with editors tools.

 

<?php function headerInfo(){ ?>
... html here ...
<?php } /* End function headerInfo */ ?>
Link to comment
Share on other sites

Actually I prefer the heredocs method for any html over a couple of lines. Makes it easy to output html code and readily accepts php vars with no tags needed!

 

My preferred format (for readability) is the following:

$code=<<<heredocs
...
..
...
heredocs;
echo $code;
No confusion there - everyone knows exactly what is going on.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.