P
P
protasovmikhail2016-07-14 19:52:13
PHP
protasovmikhail, 2016-07-14 19:52:13

How are functions inherited in PHP?

The single class is a typical singleton.
baseClass inherits the single, it has some functions:

abstract class baseClass extends single
{
  public function func1()
  {
   return __CLASS__;
  }
}

There is also a class that inherits baseClass
class class1 extends baseClass
{
 public function func2()
  {
   $this->func1(); //return - baseClass , а должен, маму его, т.е. папу, т.е. меня за ногу - class1;
  echo __CLASS__; // здесь выдаст class1
  }
}

Returns baseClass, I broke my head. I don't understand OOP? I created the base class so as not to write the same functions and variables every time. That is, if class1 and class2 inherit baseClass, then func1 is different (in my case, the difference in the returned names)
I'll go smoke .....

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey delphinpro, 2016-07-14
@protasovmikhail

php.net/manual/ru/language.oop5.late-static-bindin...

S
Sergey, 2016-07-14
Protko @Fesor

functions are not inherited.
> Returns baseClass, I broke my head.
this constant (__CLASS__) returns the name of the class in which you write the called code. If you need an instance type, use get_class($this). It will return exactly the type of instance you are working with.
p.s. Typing code to type names is a bad idea.

S
shaqster, 2016-07-14
@shaqster

I don't understand OOP?

You don't understand OOP

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question