SPL 函数 业 ,精于勤 荒于嬉.

SPL 函数 class_implements 返回指定的类实现的所有接口。

发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数

      示例1
01<?php
02interface foo {
03 }
04class bar implements foo {
05}
06print_r(class_implements(new bar));
07// since PHP 5.1.0 you may also specify the parameter as a stringprint_r(class_implements('bar'));
08function __autoload($class_name) {
09   require_once $class_name '.php';
10}
11// use __autoload to load the 'not_loaded' classprint_r(class_implements('not_loaded', true));
12?>

阅读全文 »

SPL 函数 class_parents 返回指定类的父类。

发表日期:2021-07-01 08:56:25 | 来源: | 分类:SPL 函数

      示例1
01<?php
02class foo {
03 }
04class bar extends foo {
05}
06print_r(class_parents(new bar));
07// since PHP 5.1.0 you may also specify the parameter as a stringprint_r(class_parents('bar'));
08function __autoload($class_name) {
09   require_once $class_name '.php';
10}
11// use __autoload to load the 'not_loaded' classprint_r(class_parents('not_loaded', true));
12?>

阅读全文 »

SPL 函数 class_uses Return the traits used by the given class

发表日期:2021-07-01 08:56:25 | 来源: | 分类:SPL 函数

      示例1
01<?php
02trait foo {
03 }
04class bar {
05  use foo;
06}
07print_r(class_uses(new bar));
08print_r(class_uses('bar'));
09function __autoload($class_name) {
10   require_once $class_name '.php';
11}
12// use __autoload to load the 'not_loaded' classprint_r(class_uses('not_loaded', true));
13?>

阅读全文 »

SPL 函数 iterator_apply 为迭代器中每个元素调用一个用户自定义函数

发表日期:2021-07-01 08:56:25 | 来源: | 分类:SPL 函数

      示例1
1<?php
2function print_caps(Iterator $iterator) {
3    echo strtoupper($iterator->current()) . "\n";
4    return TRUE;
5}
6$it new ArrayIterator(array("Apples""Bananas""Cherries"));
7iterator_apply($it"print_caps"array($it));
8?>

阅读全文 »

SPL 函数 iterator_count 计算迭代器中元素的个数

发表日期:2021-07-01 08:56:25 | 来源: | 分类:SPL 函数

      示例1
1<?php
2$iterator new ArrayIterator(array('recipe'=>'pancakes''egg''milk''flour'));
3var_dump(iterator_count($iterator));
4?>

阅读全文 »

SPL 函数 iterator_to_array 将迭代器中的元素拷贝到数组

发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数

      示例1
1<?php
2$iterator new ArrayIterator(array('recipe'=>'pancakes''egg''milk''flour'));
3var_dump(iterator_to_array($iterator, true));
4var_dump(iterator_to_array($iterator, false));
5?>

阅读全文 »

SPL 函数 spl_autoload_call 尝试调用所有已注册的 __autoload() 函数来装载请求类

发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数

spl_autoload_call

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

spl_autoload_call尝试调用所有已注册的 __autoload() 函数来装载请求类

说明

spl_autoload_call(string $class_name): void

可以直接在程序中手动调用此函数来使用所有已注册的 __autoload 函数装载类或接口。

参数

class_name

搜索的类名。

返回值

没有返回值。

阅读全文 »

SPL 函数 spl_autoload_extensions 注册并返回 spl_autoload 函数使用的默认文件扩展名

发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数

      示例1
1<?php
2spl_autoload_extensions(".php,.inc");
3?>

阅读全文 »

SPL 函数 spl_autoload_functions 返回所有已注册的 __autoload() 函数

发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数

spl_autoload_functions

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

spl_autoload_functions返回所有已注册的 __autoload() 函数

说明

spl_autoload_functions(): array

获取所有已注册的 __autoload() 函数。

参数

此函数没有参数。

返回值

包含所有已注册的 __autoload 函数的数组(array)。如果自动装载函数队列未激活,则返回 false。如果没有已注册的函数,则返回一个空数组。

阅读全文 »

SPL 函数 spl_autoload_register 注册给定的函数作为 __autoload 的实现

发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数

      示例1
01<?php
02// function __autoload($class) {
03//     include 'classes/' . $class . '.class.php';
04// }
05function my_autoloader($class) {
06    include 'classes/' $class '.class.php';
07}
08spl_autoload_register('my_autoloader');
09// 或者,自 PHP 5.3.0 起可以使用一个匿名函数spl_autoload_register(function ($class) {
10    include 'classes/' $class '.class.php';
11}
12);
13?>
      示例2
01<?php
02namespace Foobar;
03class Foo {
04    static public function test($name) {
05        print '[['$name .']]';
06    }
07}
08spl_autoload_register(__NAMESPACE__ .'\Foo::test');
09 // 自 PHP 5.3.0 起new InexistentClass;
10?>

阅读全文 »

SPL 函数 spl_autoload_unregister 注销已注册的 __autoload() 函数

发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数

spl_autoload_unregister

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

spl_autoload_unregister注销已注册的 __autoload() 函数

说明

spl_autoload_unregister(mixed $autoload_function): bool

从 autoload 自动装载函数队列中移除指定的函数。如果该函数队列处于激活状态,并且在给定函数注销后该队列变为空,则该函数队列将会变为无效。

如果该函数注销后使得自动装载函数队列无效,即使存在有 __autoload 函数它也不会自动激活。

参数

autoload_function

要注销的自动装载函数。

返回值

成功时返回 true, 或者在失败时返回 false

阅读全文 »

SPL 函数 spl_autoload __autoload()函数的默认实现

发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数

spl_autoload

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

spl_autoload__autoload()函数的默认实现

说明

spl_autoload(string $class_name, string $file_extensions = ?): void

本函数提供了__autoload()的一个默认实现。如果不使用任何参数调用 spl_autoload_register() 函数,则以后在进行 __autoload() 调用时会自动使用此函数。

参数

class_name

file_extensions

在默认情况下,本函数先将类名转换成小写,再在小写的类名后加上 .inc 或 .php 的扩展名作为文件名,然后在所有的包含路径(include paths)中检查是否存在该文件。

返回值

没有返回值。

阅读全文 »

SPL 函数 spl_classes 返回所有可用的SPL类

发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数

      示例1
1<?php
2print_r(spl_classes());
3?>

阅读全文 »

SPL 函数 spl_object_hash 返回指定对象的hash id

发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数

      示例1
1<?php
2$id = spl_object_hash($object);
3$storage[$id] = $object;
4?>

阅读全文 »

SPL 函数 spl_object_id Return the integer object handle for given object

发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数

      示例1
1<?php
2$id = spl_object_id($object);
3$storage[$id] = $object;
4?>

阅读全文 »

全部博文(1589)
集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。