Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does PHP allow class functions & properties to share the same name?

Tags:

php

An old colleague of mine wrote this in our code:

public function paginate() {
    return $this->paginate;
}

And I was wondering: does this return the function paginate() or the class property $paginate?

I'm guessing the latter, but it is strange that I haven't found any information on this subject.

like image 372
skerit Avatar asked Apr 03 '13 08:04

skerit


People also ask

Does PHP support class?

A PHP class, and more generally, object-oriented programming, provides additional approaches to reusability, and can be used for a variety of purposes: They can describe entities that have known properties and behaviors. They can be used as messages to functions and other objects.

Can you have functions in PHP?

PHP has more than 1000 built-in functions, and in addition you can create your own custom functions.

Is PHP class based?

Yes, the latest versions of PHP are object oriented. That is, you can write classes yourself, use inheritance, and where appropriate, the built in functionality is built in objects too (like MySQL features).


1 Answers

That returns the class property $paginate.

If it was return $this->someName();

then it returns function someName().

like image 82
Vinay Avatar answered Oct 20 '22 00:10

Vinay