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。
还有注意的是==比较两个对象的内容,===比较对象的句丙,即引用的 地址

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-

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.

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' =>

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

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 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

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

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


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools