Home > Backend Development > PHP Tutorial > Why can't subclasses inherit from parent classes?

Why can't subclasses inherit from parent classes?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-03-02 09:48:02
Original
1626 people have browsed it

Outputecho session('name')Nothing is displayed. I use {$Think.session.name}in the test template and it cannot be output. Why is this?

<code><?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller{
   public function __initialize(){
       session('name','tom');
   }
}
?>

<?php
namespace Home\Controller;
use Think\Controller;
class TestController extends CommonController{
   public function test(){
        echo session('name');
        $this->display();
    }
}
?></code>
Copy after login
Copy after login

Reply content:

Outputecho session('name')Nothing is displayed. I use {$Think.session.name}in the test template and it cannot be output. Why is this?

<code><?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller{
   public function __initialize(){
       session('name','tom');
   }
}
?>

<?php
namespace Home\Controller;
use Think\Controller;
class TestController extends CommonController{
   public function test(){
        echo session('name');
        $this->display();
    }
}
?></code>
Copy after login
Copy after login

I remember that the initialization method is _ (underscore)

The initialization method is an _ (underscore). I misunderstood it. If the subclass has an initialization function, you must indicate whether the initialization of the parent class is executed. If the initialization of the parent class is not executed automatically.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template