PHP的对象和资源
对象
对象初始化
要初始化一个对象,用 new 语句将对象实例到一个变量中。
<?phpclass foo{ function do_foo() { echo "Doing foo."; }}$bar = new foo;$bar->do_foo();?> |
转换为对象
如果将一个对象转换成对象,它将不会有任何变化。如果其它任何类型的值被转换成对象,内置类 stdClass 的一个实例将被建立。如果该值为 NULL,则新的实例为空。对于任何其它的值,名为 scalar 的成员变量将包含该值。
<?php$obj = (object) 'ciao';echo $obj->scalar; // outputs 'ciao'?> |
资源
一个资源是一个特殊变量,保存了到外部资源的一个引用。资源是通过专门的函数来建立和使用的。所有这些函数及其相应资源类型见附录。
注: 资源类型是 PHP 4 引进的。
转换为资源
由于资源类型变量保存有为打开文件、数据库连接、图形画布区域等的特殊句柄,您无法将其它类型的值转换为资源。
释放资源
由于 PHP4 Zend 引擎引进了资源计数系统,可以自动检测到一个资源不再被引用了(和 Java 一样)。这种情况下此资源使用的所有外部资源都会被垃圾回收系统释放。由此原因,很少需要用某些 free-result 函数来手工释放内存。
注: 持久数据库连接比较特殊,它们不会被垃圾回收系统破坏。

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools
