Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of New Class in PHP

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report