What is a method, property and function?

Yes, I'm struggling with that. I cannot tell them apart because every explanation I read is so obscure and philosophical enough. Can someone clarify these definitions for me? Thanks guys.

Are these definitions as applicable to procedural programming as oop? Thank.

+5
source share
6 answers

A function is a combination of commands related to each other to achieve a specific result. It can take arguments and return a result. If a function does not return a result, it is usually called a procedure. Examples:

function drawLine(x1, y1, x2, y2):
  // draws a line using Bresenham algorithm from x1,y1 to x2,y2.
  // doesn't return anything

function <number> add(a, b):
  // adds a to b and returns the result as a number
  return a + b

, . , , drawLine , .

( "-" ) , /. , Window open close, , .

- , - / getter/setter ( . , private field + get/set.).

+6

, , (, , ), , , , , :

(aka ) , , .

- , ( ) - .

- - . ( ) - "getter", "setter", . , . ( , , : , .)

+6

trim(), strlen(), fopen() ..

function myAbcFunction() { ... }

- . . - :

class MyClass {
    public $property; // Public property: $objInstance->property
    protected $property2; // Protected property

    public function doSth() {
        // That a method. $objInstance->doSth();
    }
}

.

+1

. , . .

- , , .

. - , . # .

. - , .

. - , . .

+1

- .

- , . - , . , Human "Age". , . , . - , .

0

) , , .

) , .

) , .

0

All Articles