Reputation: 627
I'm writing a little function library in PHP to simplify my routine coding tasks, and I've created a function called ghead()
, which essentially, if not passed any arguments, displays my company logo, and if populated with arguments, replaces the logo with whatever arguments have been passed.
Though, PHP keeps calling the 'Warning: Missing argument 5 for gHead(), called in...'
error when I leave the function without arguments (which is what I'm trying to do!) - is it in any way possible to disable these without modifying PHP's settings via shell or direct access? I have cPanel access only. Here's some code:
//index.php
ghead("Dashboard", "'Open Sans'", "black","0","7px"); //works
ghead(); //errors! but works, just plastered in errors ?>
<?php //functions.php
function gHead($text,$font,$colour,$shadow,$push){
if($text==""){
$text = "company-name";}
if($font==""){
$font = "'TheoremRegular'"; }
if($colour==""){
$colour = "#00FF00"; }
if($push==""){
$push = 0; }
if($shadow==""){
$shadow = "6px"; }
echo "<style>#logo {background-color:#E8E8E8; border-bottom:2px solid #C8C8C8; z-index:2; opacity:0.7; width:100%; position:absolute; left:0; top:25px; height:70px; font-family:".$font."; font-size:46px;color:".$colour."; text-shadow: 0 0 ".$shadow." #000; }.content{position:absolute;left:20px;margin-top:".$push."}#bod,#forgot_pass{background-color:#F8F8F8;position:absolute;left:0;top:95px;width:100%;height:100%;z-index:1;}</style>";
echo '<div id="logo"><div class="content">'.$text.'</div></div>'; }
Upvotes: 0
Views: 218
Reputation: 9615
I think null will be better
function gHead($text = null,$font = null,$colour = null,$shadow = null,$push = null)
Upvotes: 0
Reputation: 125640
Add default parameter values into the function declaration:
function gHead($text = "",$font = "",$colour = "",$shadow = "",$push = "")
Upvotes: 4