php小白有关问题
php小白问题
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpclass Enum{ protected $self=array(); public function _construct() { $args=func_get_args(); for($i=0,$n=count($args);$i<$n;$i++) $this->add($args[$i]); } public function _get($name=null) { return $this->self[$name]; } public function add($name=null,$enum=null) { if(isset($enum)) $this->self[$name]=$enum; else $this->sef[$name]=end($this->self)+1; }}class DefinedEnum extends Enum{ public function _construct($itms) { foreach($itms as $name=>$enum) $this->add($name,$enum); }}class FlagsEnum extends Enum{ public function _construct() { $args=func_get_args(); for($i=0,$n=count($args),$f=0x1;$iadd($args[i],$f); }}$eFruits=new Enum("APPLE","ORANGE","PEACH");echo $eFruits->APPLE.",";echo $eFruits->ORANGE.",";echo $eFruits->PEACH."\n";$eBeers=new DefinedEnum("GUINESS"=>25,"MIRROR_POND"=>49);echo $eBeers->GUINESS.",";echo $eBeers->MIRROR_POND."\n";$eFlags=new FlagsEnum("HAS_ADMIN","HAS_SUPER","HAS_POWER","HAS_GUEST");echo $eFlags->HAS_ADMIN.",";echo $eFlags->HAS_SUPER.",";echo $eFlags->HAS_POWER.",";echo $eFlags->HAS_GUEST."\n";?>
这段代码我怎么看不懂啊
哪里来的$eFruits->APPLE
$eFruits->ORANGE
$eFruits->PEACH
不要见笑啊
------解决方案--------------------
1、你先把程序修改正确了:方法名前有下划线的方法名一律改成两个下划线的
如 _construct 改为 __construct
2、修改 __get 方法成这样
public function __get($name=null)
{
echo "读取属性 $name";
return $this->self[$name];
}
3、运行修改后的代码,你就可以知道是怎么回事了
------解决方案--------------------
- PHP code
class Enum{ protected $self=array(); public function __construct() { $args=func_get_args(); for($i=0,$n=count($args);$iadd($args[$i]); } public function __get($name=null) { return $this->self[$name]; } public function add($name=null,$enum=null) { if(isset($enum)){ $this->self[$name]=$enum; }else{ $this->self[$name]=end($this->self)+1; } }}class DefinedEnum extends Enum{ public function __construct($itms) { foreach($itms as $name=>$enum) $this->add($name,$enum); }}class FlagsEnum extends Enum{ public function __construct() { $args=func_get_args(); for($i=0,$n=count($args),$f=0x1;$iadd($args[$i],$f); } }} $eFruits=new Enum("APPLE","ORANGE","PEACH");echo $eFruits->APPLE.",";echo $eFruits->ORANGE.",";echo $eFruits->PEACH."\n";$eBeers=new DefinedEnum(array("GUINESS"=>25,"MIRROR_POND"=>49));echo $eBeers->GUINESS.",";echo $eBeers->MIRROR_POND."\n"; $eFlags=new FlagsEnum("HAS_ADMIN","HAS_SUPER","HAS_POWER","HAS_GUEST");echo ($eFlags->HAS_ADMIN).",";echo ($eFlags->HAS_SUPER).",";echo $eFlags->HAS_POWER.",";echo $eFlags->HAS_GUEST."\n";<br><font color="#e78608">------解决方案--------------------</font><br>两个下划线就都对了。<div class="clear"> </div>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

How to use the enum module to define enumeration types in Python2.x Introduction: An enumeration is a data type that limits the value of a variable to a limited range. Using enumeration types can make the code clearer and more readable. In Python2.x, we can use the enum module to define enumeration types. This article will introduce how to use the enum module to define and use enumeration types, and give corresponding code examples. Importing the enum module Before using the enum module, you first need to import the module. exist

In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets

The most popular Go frameworks at present are: Gin: lightweight, high-performance web framework, simple and easy to use. Echo: A fast, highly customizable web framework that provides high-performance routing and middleware. GorillaMux: A fast and flexible multiplexer that provides advanced routing configuration options. Fiber: A performance-optimized, high-performance web framework that handles high concurrent requests. Martini: A modular web framework with object-oriented design that provides a rich feature set.

In C#, the enumeration type is a very useful data type that allows us to define some constants to represent certain states or options. Once the enum type is defined, you can use the Enum.GetNames function to get all defined names. This article details how to use this function and provides specific code examples. What is the Enum.GetNames function The Enum.GetNames function is a static method that returns an array of strings of the specified enumeration type, where each string represents the

Detailed explanation of the role and usage of the echo keyword in PHP PHP is a widely used server-side scripting language, which is widely used in web development. The echo keyword is a method used to output content in PHP. This article will introduce in detail the function and use of the echo keyword. Function: The main function of the echo keyword is to output content to the browser. In web development, we need to dynamically present data to the front-end page. At this time, we can use the echo keyword to output the data to the page. e
