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

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

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

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

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-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

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

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.

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

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov
