Login   Register  
PHP Classes

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Marko Schulz  >  Eastern  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example file to show the usage of the Eastern class
Class: Eastern
Calculate the Easter related dates
Author: By
Last change: Sample script slightly extended.
Date: 3 years ago
Size: 1,651 bytes


Class file image Download
    <title>Simple example Easter class</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />



// variables for Easter class
$cfg['easter'] = array(
'year' => 2009,
'format' => 'jS F'

// load the Easter class

// simple example
try {
$year 2011;
// get the $easter object an set the year
(object) $easter = new Easter($cfg['easter']);

"<h3>About Carl Friedrich Gauss</h3>\n<p>".$easter->about()."</p>\n";

    try {
        if ( 
$easter->setVar('year',$year) === FALSE )
            throw new 
Exception('Invalid parameter');
    } catch ( 
Exception $varError ) {
"Error: <b>"$varError->getMessage(). "</b> on line "$varError->getLine(). " in "$varError->getFile(). "<br/>\n";

// output
echo "<h3>Simple example</h3>\nIn $year:<br/> Good Friday is on "$easter->date('goodfriday'). ", <br/>";
"Easter Sunday on "$easter->date('eastersunday'). " and <br/>Easter Monday on "$easter->date('eastermonday'). ".<br/>\n";

// show class variables
$varYear   $easter->getVar('year');
$varEaster $easter->getVar('easter');
$varFormat $easter->getVar('format');
"<h3>Class variables:</h3>\nYear = ".$varYear."<br/> Easter = ".$varEaster."<br/> Format = ".$varFormat."<br/>\n";

    if ( 
$varTest $easter->getVar('fail') === FALSE // test failure of call to getVar()
throw new Exception('getVar() failed');

} catch ( 
Exception $error ) {
"Error: "$error->getMessage(). " on line: "$error->getLine(). " in "$error->getFile(). "<br/>\n";