search

1,魔术常量,有很多,总结之
   A 识别脚本运行时的位置或名称等
    _LINE_  返回当前行号
    _FILE_  返回当前脚本的完整路径和文件名,包含一绝对路径
    _FUNCTION_  返回该函数被定义时的名字(大小写敏感)
    _CLASS_   类名称,返回该类别定义时的名字(大小写敏感)
    _METHOD_   类的成员方法名称(大小写敏感)
    class MagicTest {
      //返回当前函数的名称
     function test_function() {
         return __FUNCTION__;
     }
     //返回当前类的名字
     function test_class() {
         return __CLASS__;
     }
     //返回当前方法的名字
     function test_method() {
         return __METHOD__;
     }
 }
 echo "_LINE_运行时的所在行号: ".__LINE__."
";
 echo "当前PHP脚本的完整路径: ".__FILE__."
";
 echo "当前执行的类名: ".MagicTest::test_class()."
";
 echo "当前执行的函数名: ".MagicTest::test_function()."
";
 echo "当前类的方法名: ".MagicTest::test_method()."
";
?>
    还有OOP里的魔术
   _get()与_set(),_call(),当试图写入一个不存在或不可见的属性时,会执行_set()方法,如
   class myShop {
   private $p = array();
  
    function __set($name, $value) { //取得属性名称和值
      echo "set::$name:$value
";
     $this->p[$name] = $value;
   }
  
   function __get($name) { //取得属性名称
     print "get::$name
";
     return array_key_exists($name,$this->p) ? $this->p[$name] : null;
   }
 }
 
 $shop = new MyShop();
 $shop->apple = 2;
 $shop->pear = 3;
 $shop->pear++;
 echo "苹果=". $shop->apple. "
";
 echo "梨=". $shop->pear. "
";
?>
 
2 PHP里的CLONE()
    class MyClass {
  public $var = 1;
 }
 $obj1 = new MyClass();
 $obj2 = $obj1;
 $obj2->var = 2;
 print $obj1->var;
?>
    PHP4中上面的输出1,$obj2将值全部赋给$obj1,是建立对象的副本;但PHP5中,$obj1被当一个对象引用处理,当$obj2的值改变时,实际上修改的
是$obj的引用,所以输出2。
  还有注意的是==比较两个对象的内容,===比较对象的句丙,即引用的 地址

Statement
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
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

How to Register and Use Laravel Service ProvidersHow to Register and Use Laravel Service ProvidersMar 07, 2025 am 01:18 AM

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Customizing/Extending Frameworks: How to add custom functionality.Customizing/Extending Frameworks: How to add custom functionality.Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools