TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 01-14-2012, 03:50 AM   #1 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default OOP vs Procedural

What are the advantages of using oop over procedural ?

Take the following function, and if I were to make this into a class (which I have no idea how to yet!) what would I gain ?

This is to find out the current week number for a company financial year, 4th April 2011 being week 1

PHP Code:
<?php

date_default_timezone_set
('Europe/London');

function 
longDate($uk_date$sep){
    
    list(
$day$month$year) = explode($sep$uk_date); 
$usdate $month.'/'.$day.'/'.$year
return 
date("l, F jS, Y",strtotime($usdate));
    
    
}

function 
getCurrentWeek($type){
$week_secs 604800;
// uk format dd/mm/yyyy
$week1 '04/04/2011';

list(
$day$month$year) = explode('/'$week1);

$startFinYear gmmktime(0,0,0,$month$day$year);

// current unix time
$currTime strtotime('now');

$weekDiff floor(($currTime $startFinYear)/$week_secs);
$timeDiff $currTime $startFinYear;

$shortDate date('d/m/Y'strtotime("+" $weekDiff " week",$startFinYear ));
$longDate longDate(date('d/m/Y'strtotime("+" $weekDiff " week",$startFinYear )), '/');

switch(
$type){
    case 
'short':
        return 
$shortDate;
        break;
    case 
'long' :
        return 
$longDate;
        break;
    default:
        return 
$weekDiff;
        break;
    }


}

echo 
getCurrentWeek('') . "<br />";
echo 
getCurrentWeek('short') . "<br />";
echo 
getCurrentWeek('long') . "<br />";
?>
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
What design pattern? Haris Absolute Beginners 9 10-02-2007 01:14 AM


All times are GMT. The time now is 05:20 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design