V
V
VS2018-12-26 16:11:40
PHP
VS, 2018-12-26 16:11:40

What does $this-> -> mean in PHP?

Friends, good day!
Thanks in advance for your help and patience with a strangely worded question! :)
Studying PHP (self-taught, I've been teaching for about 3 months, without mentors - training is decently delayed), I decided to master the framework, so that seeing ready-made solutions - it's better to master new or stagnant material.
After some time, I understood static and other classes, features, and so on. (although I'm still floundering in the use of interfaces and cloning).
In the framework (I decided to start with fuel php, because it seemed to me to have readable code) I came across a similar line, then another one, and realized that it was teeming with expressions
$this->something -> even more specific = meaning.
example:
$this->template->title = 'Title of our page';
$this->template->content = View::forge('test/index...
What is this syntax?
How can I find out where to read what kind of construct this is?
$this-> do we have a class name here? -> and here method?
Tell me, please, or indicate where you can learn more about this issue of "layers" in PHP?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
FanatPHP, 2018-12-26
@defect00

1. Bury Fuel back into his grave and no longer disturb the ashes of this old man who died in ancient times.
2. Instead, learn Laravel
3. Discover the PHP documentation and refer to it in incomprehensible cases. It's hard to believe, of course, but everything is written there . This link is two clicks away for "PHP OOP"
To be honest, I myself often catch myself on such "lazy brain". When you can 100% find the answer yourself, but it's easier to ask a knowledgeable person. but here it is important not to succumb, and first try on your own. To do this, in any question there should be a phrase - "I was looking for something like this", but I did not find it. In the process of writing this phrase, the answer itself is found. As a result, time will be saved, experience will be gained and there will be less garbage on the Internet.

S
Stalker_RED, 2018-12-26
@Stalker_RED

In general, a cool move is to study frameworks without reading a word about OOP.
$thisusually points to an instance of the class, and after the "arrow" a method or property.
This technique with call chains is called "method chaining".
You can read the documentation php.net/manual/ru/language.oop5.php
Or some textbook, where they will tell you in a more "living" language.

D
Denis, 2018-12-26
@sidni

$this->template->content
in this case, the current class has a field (in this case, not a method, but you can do this with methods called chain ( https://stackoverflow.com/questions/3724112/php-me... )) template which is in its own in its own queue an instance of some class that has a content field

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question