 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
06-29-2009, 07:52 PM
|
#1 (permalink)
|
|
The Acquainted
Join Date: May 2009
Posts: 178
Thanks: 9
|
Fatal error: Cannot redeclare...
Any ideas why I am getting this error? Cant understand why I am getting it I am calling a function called validateTime twice in the same class but then i also call a date function i have written twice within the same class and dont get the error for that:
Quote:
|
Originally Posted by PHP
Fatal error: Cannot redeclare validatetime() (previously declared in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\betgame\lib\date.funct ions.php:77) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\betgame\lib\date.funct ions.php on line 77
|
Last edited by Wildhoney : 06-29-2009 at 08:24 PM.
|
|
|
|
06-29-2009, 07:53 PM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
can we see the code?
|
|
|
|
06-29-2009, 08:47 PM
|
#3 (permalink)
|
|
The Acquainted
Join Date: May 2009
Posts: 178
Thanks: 9
|
Class:
PHP Code:
<?php
class Bet {
public $bettype;
public $eventdetail;
public $eventtype;
public $eventdate;
public $eventtime;
public function validate_add_bet($bettype,$eventdetail,$eventtype,$eventdate,$eventtime,$freezedate,$freezetime) {
$this->bettype = $bettype;
$this->eventdetail = $eventdetail;
$this->eventtype = $eventtype;
$this->eventdate = $eventdate;
$this->eventtime = $eventtime;
$this->freezedate = $freezedate;
$this->freezetime = $freezetime;
$this->validate_event_detail($this->eventdetail);
$this->validate_event_date($this->eventdate);
$this->validate_event_time($this->eventtime);
$this->validate_freeze_date($this->freezedate);
$this->validate_freeze_time($this->freezetime);
$this->addbet($this->bettype,$this->eventdetail,$this->eventtype,$this->eventdate,$this->eventtime,$this->freezedate,$this->freezetime);
}
public function validate_event_detail($eventdetail) {
$this->$eventdetail = $eventdetail;
}
public function validate_event_date($eventdate) {
$this->$eventdate = $eventdate;
try {
validateUkFormat($this->$eventdate);
$this->$eventdate = getMysqlDate($this->$eventdate);
} catch ( Exception $e ) {
die ( $e->__toString() );
}
}
public function validate_event_time($eventtime) {
$this->$eventtime = $eventtime;
try {
validateTime($this->$eventtime);
} catch ( Exception $e ) {
die ( $e->__toString() );
}
}
public function validate_freeze_date($freezedate) {
$this->$freezedate = $freezedate;
try {
validateUkFormat($this->$freezedate);
$this->$freezedate = getMysqlDate($this->$freezedate);
} catch ( Exception $e ) {
die ( $e->__toString() );
}
}
public function validate_freeze_time($freezetime) {
$this->$freezetime = $freezetime;
try {
validateTime($this->$freezetime);
} catch ( Exception $e ) {
die ( $e->__toString() );
}
}
/* Add bet */
public function addbet($bettype,$eventdetail,$eventtype,$eventdate,$eventtime) {
$this->bettype = $bettype;
$this->eventdetail = $eventdetail;
$this->eventtype = $eventtype;
$this->eventdate = $eventdate;
$this->eventtime = $eventtime;
$query = ("INSERT INTO bet (betoriginator,colid,betdate,bettime,bettype,eventdetail,eventtype,eventdate,eventtime,freezedate,freezetime,status)
VALUES ('captainmerton',1,'2009-06-10','19:00:00','test','$this->eventdetail','$this->eventtype','2009-06-10','19:00:00','2009-06-10','19:00:00','E')");
$result = mysql_query($query) OR die('Cannot perform add bet query!');
}
}
?>
Function:
PHP Code:
function validateTime($time)
{
$tPieces = explode(":",$time);
$hour = $tPieces[0];
$min = $tPieces[1];
$sec =$tPieces[2];
if (($hour < 0) || ($hour > 24)) {throw new Exception("Hours must be between 00 and 24");
} else {
if (($min < 0) || ($min > 60)) {throw new Exception("Mins must be between 00 and 60");
} else {
if (($sec < 0) || ($sec > 60)) {throw new Exception("Secs must be between 00 and 60");}
}
}
}
|
|
|
|
06-29-2009, 08:58 PM
|
#4 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
That PHP code doesn't contain the function validateTime. However, if you look in date.functions.php you will find one instance of it, and possibly another one as well. There is definitely another one somewhere, but where it is I don't know at this point.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
06-29-2009, 09:07 PM
|
#5 (permalink)
|
|
The Acquainted
Join Date: May 2009
Posts: 178
Thanks: 9
|
Here are the functions:
PHP Code:
<?php
function dateDiff($dformat, $endDate, $beginDate)
{
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
$end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
return $end_date - $start_date;
}
function getUkDate($date)
{
$date_parts=explode('-', $date);
return $date_parts[2].'-'.$date_parts[1].'-'.$date_parts[0];
}
function getMysqlDate($date)
{
$date_parts=explode('/', $date);
return $date_parts[2].'-'.$date_parts[1].'-'.$date_parts[0];
}
function getAge($dob)
{
$todays_date = date("Y-m-d");
$unixtoday = strtotime($todays_date);
$unixdob = strtotime($dob);
return floor(($unixtoday - $unixdob)/31556926);
}
function validateUkFormat($date)
{
$todays_date = date("Y/m/d");
$strdate1=$date;
//Check the length of the entered Date value
if((strlen($strdate1)<10)OR(strlen($strdate1)>10)){
throw new Exception("Date must be in 'dd/mm/yyyy' format");
} else {
//The entered value is checked for proper Date format
if((substr_count($strdate1,"/"))<>2){
throw new Exception("Date must be in 'dd/mm/yyyy' format");
} else {
$pos=strpos($strdate1,"/");
$date=substr($strdate1,0,($pos));
$result=ereg("^[0-9]+$",$date,$trashed);
if(!($result)){throw new Exception("Date must be in 'dd/mm/yyyy' format");}
else{
if(($date<=0)OR($date>31)){throw new Exception("Day must be between 1 and 31");}
}
$month=substr($strdate1,($pos+1),($pos));
if(($month<=0)OR($month>12)){throw new Exception("Month must be between 1 and 12");}
else{
$result=ereg("^[0-9]+$",$month,$trashed);
if(!($result)){throw new Exception("Date must be in 'dd/mm/yyyy' format");}
}
$year=substr($strdate1,($pos+4),strlen($strdate1));
$result=ereg("^[0-9]+$",$year,$trashed);
if(!($result)){throw new Exception("Invalid Year");}
}
}
function validateTime($time)
{
$tPieces = explode(":",$time);
$hour = $tPieces[0];
$min = $tPieces[1];
$sec =$tPieces[2];
if (($hour < 0) || ($hour > 24)) {throw new Exception("Hours must be between 00 and 24");
} else {
if (($min < 0) || ($min > 60)) {throw new Exception("Mins must be between 00 and 60");
} else {
if (($sec < 0) || ($sec > 60)) {throw new Exception("Secs must be between 00 and 60");}
}
}
}
}
?>
|
|
|
|
06-29-2009, 09:04 PM
|
#6 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
You're not including the date.functions.php more than once are you, by any chance?
|
|
|
|
06-29-2009, 09:24 PM
|
#7 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Quote:
Originally Posted by Salathe
You're not including the date.functions.php more than once are you, by any chance?
|
I had thought, too, but the function he's shown us is called validateTime and the one it's throwing an error at is validatetime. I don't think PHP would change the case of the function, would it?
I think the two functions are: validatetime and validateTime. The mismatch in cases seem to suggest it's not a double include.
Naturally I could be wrong.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
06-29-2009, 09:09 PM
|
#8 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
Your declaring validateTime($time) but using it as validatetime($time).
Maybe your including the file more than once?
|
|
|
|
06-29-2009, 09:54 PM
|
#9 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
I've had some instances where PHP will be case sensitive for function names. Maybe its a "stricter" setting on his php.ini?
|
|
|
|
06-30-2009, 01:13 AM
|
#10 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Posts: 166
Thanks: 0
|
Quote:
Originally Posted by Salathe
You're not including the date.functions.php more than once are you, by any chance?
|
Quote:
Originally Posted by adamdecaf
Maybe your including the file more than once?
|
That would be my guess since it is saying both functions are on the same line in the same file.
Quote:
|
Originally Posted by WildHoney
I think the two functions are: validatetime and validateTime. The mismatch in cases seem to suggest it's not a double include.
|
http://www.php.net/manual/en/functions.user-defined.php
The note down near the bottom says:
"Note: Function names are case-insensitive, though it is usually good form to call functions as they appear in their declaration."
__________________
Eric
|
|
|
|
06-30-2009, 01:22 AM
|
#11 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Oh I understand this very well. That is why I am trying to throw solutions in.
However, I thought PHP would take the function as he wrote it. For instance, if he had mytest and myTest, that if the second one was the last function to be loaded, then it would say cannot redeclare myTest, but it appears PHP converts all the function names to lower-case anyway when displaying the errors.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
06-30-2009, 04:07 AM
|
#12 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
Hmm, then is it down to a duplication of file includes?
|
|
|
|
06-30-2009, 04:18 AM
|
#13 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
it's simple it's a file includes thing as you all stated i am sure of it..
check your includes..
|
|
|
|
06-30-2009, 08:44 AM
|
#14 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
If you are still getting the error, captainmerton, please repeat exactly what the error says. Also, the file that you provided above cannot be right since line 77 where the error is occurring contains $sec =$tPieces[2]; inside the validateTime function.
|
|
|
|
06-30-2009, 11:47 AM
|
#15 (permalink)
|
|
The Acquainted
Join Date: May 2009
Posts: 178
Thanks: 9
|
include of date.functions.php and instantiation of bet form which in turn instatiates bet object which uses the validateTime() function i have looked but cannot see more than 1 include of the date.functions.php script feel like i am losing my marbles:
PHP Code:
<div id="loggedin">
<p><a href="logout.php">Logout</a></p>
<p>
<?php
try {
require_once('./lib/date.functions.php');
require_once('./lib/tablewriter.class.php');
require_once('./lib/formprocessor.class.php');
require_once('./lib/bet.class.php');
$tblWriter = new OnlineNowTable($_SESSION['name']); //create a new object
$tblWriter->writeTable(); //run the writeTable method
$tblWriter2 = new UserDetailTable($_SESSION['name']); //create a new object
$tblWriter2->writeTable(); //run the writeTable method
$tblWriter2 = new CollectiveMembersTable($_SESSION['name']); //create a new object
$tblWriter2->writeTable(); //run the writeTable method
$betform = new BetForm(); //create a new object
}
catch(Exception $error) {
print $error->getMessage();
}
?>
</p>
</div>
|
|
|
|
06-30-2009, 11:59 AM
|
#16 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
See, another thing that makes me think it's not a double include is that surely PHP would see the function at the top, and be unable to redeclare that. Rather, it is failing at the last function in the file which is even more curious.
I say it cannot be a double include from that. What does everybody else think?
You must be creating that function elsewhere. Unless something else is creating that function which is out of your control. Perhaps a PHP module of some sort that nobody else has here.
Try adding the following code about your require_once statements, to see if the function exists. And then if it doesn't exist there, try and move it in between the require_once statements, one at a time.
php Code:
if (function_exists('validateTime')){ die('It already exists... But where?'); }
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
06-30-2009, 01:27 PM
|
#17 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Could you zip all of your files up and email them to me (salathe[hat]php.net)? It's probably a simple problem but no-one here has been given the full picture yet.
|
|
|
|
07-01-2009, 02:33 PM
|
#18 (permalink)
|
|
The Acquainted
Join Date: May 2009
Posts: 178
Thanks: 9
|
I think I've cracked it. From some crude de-bugging i found that I had included the validatetime function inside the function above it validateUkFormat because of incorrect { } brackets so i think i was declaring it more than once by doing that. It had driven me nuts but is now resolved by. Thanks for all your help. I really ought to be using an editor - any guidelines of which one to use?
Here's the updated functions include:
PHP Code:
/**
* @name PHP 5 General Date Functions
* @version 1.0
**/
function dateDiff($dformat, $endDate, $beginDate)
{
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
$end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
return $end_date - $start_date;
}
function getUkDate($date)
{
$date_parts=explode('-', $date);
return $date_parts[2].'-'.$date_parts[1].'-'.$date_parts[0];
}
function getMysqlDate($date)
{
$date_parts=explode('/', $date);
return $date_parts[2].'-'.$date_parts[1].'-'.$date_parts[0];
}
function getAge($dob)
{
$todays_date = date("Y-m-d");
$unixtoday = strtotime($todays_date);
$unixdob = strtotime($dob);
return floor(($unixtoday - $unixdob)/31556926);
}
function validateUkFormat($date)
{
$todays_date = date("Y/m/d");
$strdate1=$date;
//Check the length of the entered Date value
if((strlen($strdate1)<10)OR(strlen($strdate1)>10)){
throw new Exception("Date must be in 'dd/mm/yyyy' format");
} else {
//The entered value is checked for proper Date format
if((substr_count($strdate1,"/"))<>2){
throw new Exception("Date must be in 'dd/mm/yyyy' format");
} else {
$pos=strpos($strdate1,"/");
$date=substr($strdate1,0,($pos));
$result=ereg("^[0-9]+$",$date,$trashed);
if(!($result)){throw new Exception("Date must be in 'dd/mm/yyyy' format");}
else{
if(($date<=0)OR($date>31)){throw new Exception("Day must be between 1 and 31");}
}
$month=substr($strdate1,($pos+1),($pos));
if(($month<=0)OR($month>12)){throw new Exception("Month must be between 1 and 12");}
else{
$result=ereg("^[0-9]+$",$month,$trashed);
if(!($result)){throw new Exception("Date must be in 'dd/mm/yyyy' format");}
}
$year=substr($strdate1,($pos+4),strlen($strdate1));
$result=ereg("^[0-9]+$",$year,$trashed);
if(!($result)){throw new Exception("Invalid Year");}
}
}
}
function validateTime($time)
{
$tPieces = explode(":",$time);
$hour = $tPieces[0];
$min = $tPieces[1];
$sec =$tPieces[2];
if (($hour < 0) || ($hour > 24)) {throw new Exception("Hours must be between 00 and 24");
} else {
if (($min < 0) || ($min > 60)) {throw new Exception("Mins must be between 00 and 60");
} else {
if (($sec < 0) || ($sec > 60)) {throw new Exception("Secs must be between 00 and 60");}
}
}
}
|
|
|
|
07-01-2009, 04:11 PM
|
#19 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
Notepad++ Works great, but others seem to have better designs (at the loss of language support).
|
|
|
|
07-01-2009, 04:25 PM
|
#20 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Better indenting would have made this problem clear in an instant (there or there abouts)! Rather than having most things all mushed together along one vertical axis, follow a strict indenting system to make your code blocks much clearer.
Compare:
PHP Code:
function moo($lady = FALSE) { // This function moos! if ($lady) { steal_some_milk(); return ladylike_moo(); } return big_manly_moo(); }
To:
PHP Code:
function moo($lady = FALSE) { // This function moos! if ($lady) { steal_some_milk(); return ladylike_moo(); } return big_manly_moo(); }
Multiply that by 10 or 100 for a file full of code (wow, lots of moos!).
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|