Difference between object and class in PHP?

后端 未结 3 1907
谎友^
谎友^ 2020-12-28 14:50

What is the difference between Object and Class in PHP? I ask because, I don\'t really see the point to both of them.

Can you tell me the difference with a g

3条回答
  •  余生分开走
    2020-12-28 15:16

    For the new developers:

    Class

    A class is a collection of method and variables

    class Test{
    
      const t = "OK";
      var $Test;
      function TestFunction(){
    
      }
    }
    

    Object

    Object is a instance of a class (when you want to use your class and the thing you create)

    $test = new Test();
    $test->TestFunction();//so here you can call to your class' function through the instance(Object)
    

提交回复
热议问题