What is Method, Property and Function?

后端 未结 6 1387
失恋的感觉
失恋的感觉 2021-01-02 08:48

Yeah, I\'m struggling with that. I cannot distinguish among them because every explanation I read is so unclear and philosophical enough. Can someone clear up these definiti

6条回答
  •  情歌与酒
    2021-01-02 09:34

    Function is a standalone construction like trim(), strlen(), fopen() etc.

    function myAbcFunction() { ... }
    

    Method is a function of object. It is defined in class. Property is just property of object:

    class MyClass {
        public $property; // Public property: $objInstance->property
        protected $property2; // Protected property
    
        public function doSth() {
            // That's a method. $objInstance->doSth();
        }
    }
    

    I suggest read the manual Classes and Objects chapter.

提交回复
热议问题