Forum Moderators: coopster

Message Too Old, No Replies

calendars

         

nshack31

10:29 am on Jan 22, 2005 (gmt 0)

10+ Year Member



I'm trying to create a calendar and have this script..

<?php

function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array())
{
$time = time();
echo generate_calendar(date('Y', $time), date('n', $time));}
?>

I am calling a function from within a function so it is printing a blank page :( where do I need to place this code in order for it to work?....

echo generate_calendar(date('Y', $time), date('n', $time));}

mincklerstraat

10:58 am on Jan 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are some problems here which are probably causing the 'blank page'. This isn't such a bad thing though.

If you add:


error_reporting(E_ALL);

to your script while you're developing it (remove when you deploy), you'll be able to see what errors PHP is generating.

First problem here is probably

$pn = array()
. This occurs in a default variable value inside the declaration of a function. Strictly speaking, this is a no-no - default variable values in function declarations are only supposed to be static integers, floats, and strings - no variables, functions, or fancy stuff allowed here. If PHP isn't generating an error here, it may well in a future of PHP, since this is not allowed by the manual, and PHP is a language that tries to stick to the manual.

Second problem - very big problem - you call this function within itself (the very same function), without having any in-built limits. So this is an infinitely recursing function - a function which will just keep calling itself, and keep calling itself, and keep calling itself. If you have an older version of PHP, this might even cause your server to crash.

Recursive functions are touchy beasts and you really should try your best to avoid writing recursive functions until you are very comfortable indeed with PHP and have an excellent intuitive grasp of how things in it work. You know you're on this level when this forum's mods address you as "d00d" and formulate replies to you in leet script.

See instead if you can't re-write this function to just loop through an array. If you can't avoid a function that uses recursion, make sure it has a level variable in the function arguments that is augmented +1 every time the function is executed, and before the function calls itself again, checks this variable to make sure it isn't above a certain level max (and make that level max a pretty low number, too).

nshack31

11:55 am on Jan 22, 2005 (gmt 0)

10+ Year Member



hi, yes I use error_reporting(E_ALL); but it is still blank! I'll try and decode your comments to my pathetic level of understanding and I'll give it a shot!

Thanks for that :)

nshack31

11:58 am on Jan 22, 2005 (gmt 0)

10+ Year Member



I found some calendar code

however, this is the code but does not print the calendar out. What variables are required to prinout calendar code, as it too displays a blank page!

[edited by: jatar_k at 6:21 pm (utc) on Jan. 22, 2005]
[edit reason] removed url [/edit]

grandpa

12:13 pm on Jan 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I found some calendar code here...

As long as you are looking for calendar code, you might want to look at some calendar classes. I looked into what it might take to write my own calendar and decided, in this case, there was no reason to re-invent the wheel. The class objects already exist in the public domain. If you need help locating a calendar class sticky me for the url... not too sure about dropping it here.