Using Classes / OOP in PHP

Posted by Alex Demchak on Stack Overflow See other posts from Stack Overflow or by Alex Demchak
Published on 2012-09-01T03:14:41Z Indexed on 2012/09/01 3:38 UTC
Read the original article Hit count: 159

Filed under:
|

I'm pretty proficient with PHP, outside of OOP - which I am just now starting to jump in to.

I've been watching videos and reading tutorials, but they are all still pretty confusing...

If I have

FILE 1 (class.time.php)

class Time {
    function GetTime(){
        $time = date('H:i:s');
        printf($time);
    }
}

and then in a nother php page I've got

FILE 2 (page.php)

I can do

include('class.time.php');

and then anywhere in this page I can then do

$time = new Time; //Calling the class and setting the class to a variable
$time->GetTime(); //This is BASICALLY saying (run the 'GetTime' function in the 'Time Class'

My main question is, is the comment above (This is BASICALLY saying.....) correct? or is there a better way to think of it?

© Stack Overflow or respective owner

Related posts about php

Related posts about oop