Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8465193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:58:18+00:00 2026-06-10T14:58:18+00:00

I’m pretty proficient with PHP, outside of OOP – which I am just now

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:58:20+00:00Added an answer on June 10, 2026 at 2:58 pm

    regarding method calls

    I would make one correction to your statement, hinting a little more accurately at what Object Orientation is all about. Your comment reads:

    run the ‘GetTime’ function in the ‘Time Class’

    Which is only kinda accurate, and expounding on it may clarify OOP for you. For the purposes of this post, I might rephrase it this way:

    run the ‘GetTime’ method (which is defined in the Time class) bound to the object stored in $time

    See the difference? You aren’t just calling a function from a class, you are saying “get the processing instructions from the class, but bind those instructions to this specific object and then execute.

    It may sound like mincing words, but it’s critical to understanding encapsulation. Objects of a class share their method definitions, but they do not share data.

    You can think of an object as essentially a set of two things:

    1. A block of memory holding it’s own, personal data
    2. A pointer to a set of methods with special access to that data

    (the “special” nature of the methods’ relationship to the data is either implicit or explicit, it’s up to you)

    The distinction is readily evident when you start using “member variables” (sometimes called “object properties”, “instance variables (aka ivars)”, or similar names). Consider this sample code:

    class Person {
      public $name;
      public printName() {
        echo $this->name;
      }
    }
    
    $me = new Person();
    $you = new Person();
    
    $me->name = "Chris";
    $you->name = "Alex";
    
    $me->printName(); // "Chris"
    $you->printName(); // "Alex"
    

    This highlights the fact that each object has it’s own memory for instance variables. They share the definition of those variables, as well as the blocks of code written to process those variables.

    The special variable $this is of particular interest to my overall intention with this answer: the same variable in the same method definition actually points to a different object depending on which object you call the method on.

    regarding new

    Now to the previous line, where your comment reads (in regard to $time = new Time):

    Calling the class and setting the class to a variable

    The way I would phrase it is:

    Make an instance of this class, and allow me to access the instance through $time

    That word, instance will be a big concept to get solid before moving on. You don’t call a class, you call a method, and you don’t (in PHP at least) set the value of variables to be a class, you set them to point to instances of the class. Sometimes people use the words instance and object interchangeably, which is fine. But you should not use them interchangeably with the word class.

    Let’s get technical:

    When you use the new operator, technically you are telling PHP to do two things:

    1. grab some fresh memory, exactly enough to store all the member variables defined in the class
    2. call a special method on that new object to allow me to initialize my object

    So if you call new twice, you grab enough memory for 2 objects, and so on. PHP uses your class definition to figure out how much memory to allocate for you, and find the special method to call.

    That special method is called __construct, and is guaranteed to be called when your objects are created, with that special $this variable pointing to your shiny new memory. Here’s a sample of how you might use it:

    class Foo {
     private $createdTime;
     public function __construct() {
      $this->createdTime = time();
     }
    }
    
    $myFoo = new Foo;
    

    Even though you don’t see it, __construct() was called and the value of $createdTime was initialized.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.