Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of New Class in PHP

Shulou Source: shulou.com Published: 2022-06-03 09:08:35 09月19日 Update

The main content of this article is "how to solve the new class problem of PHP". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the new class problem of PHP.

Index.php file

Function _ _ autoload ($_ className) {require $_ className.'.class.php';} / / create a new class If (isset ($_ GET ['index'])) {$m=new Main ($_ GET [' index']);} else {$m=new Main ();} include $m-> ui ()

Main.class.php file

Class Main {private $index;// constructor to initialize data public function _ construct ($index='') {$this- > index=$index;} / / ui function include corresponding include file public function ui () {if (empty ($this- > index) | |! file_exists ($this- > index.'.inc')) {$this- > index='start';} return $this- > index.'.inc';}}

What's the meaning of the scarlet letter: the constructor parameter value in the class has been set to empty by default (public function _ construct ($index='')), why can't you just write $m=new Main ($_ GET ['index']);. If you don't want to do the if judgment of the scarlet letter in index, what do you need to write in the class? Thank you. I don't quite understand.

-solution ideas--

If (isset ($_ GET ['index']) {$m=new Main ($_ GET [' index']); / / if $_ GET ['index'] exists, take $_ GET [' index'] as the parameter} else {$m=new Main (); / / otherwise use the default parameter}

Direct use of $_ GET ['index'] may cause a NOTICE level error

Indiscriminate use of incoming data may cause security problems

-solution ideas--

I changed it a little bit. What do you think?

Step 2, the use of the function. For example, create a test.txt file and write the content "abc" as follows:

At this point, I believe you have a deeper understanding of "how to solve the new class problem of PHP". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Files functions content questions ideas generation code parameters data methods steps scarlet letter project learning practical deeper security interest addition practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Linux Xiaomi OPPO Reno Shulou Information