当前位置: 首页 > news >正文

饿了么网站开发南京seo收费

饿了么网站开发,南京seo收费,网站建设的软件介绍,做网站的怎么认证微博一 自动加载 1.1 __autoload(string $class) 类自动加载,7.2版本之后废弃。可使用sql_autoload_register()注册方法实现。 类自动加载,无返回值。 #php7.2之前function __autoload($class) {if(strpos($class, CI_) ! 0){if (file_exists(APPPATH . …

一 自动加载

1.1 __autoload(string $class)

类自动加载,7.2版本之后废弃。可使用sql_autoload_register()注册方法实现。

类自动加载,无返回值。

#php7.2之前function __autoload($class)
{if(strpos($class, 'CI_') !== 0){if (file_exists(APPPATH . 'core/'. $class . EXT)) {@include_once( APPPATH . 'core/'. $class . EXT );}elseif(file_exists(LIBS_PATH . 'core/'. $class . EXT)) {@include_once( LIBS_PATH . 'core/'. $class . EXT );}}
}

1.2 spl_autoload_functions()

获取已注册的函数。返回数组。

1.3 spl_autoload_unregister(callable $callback)

注销已注册的函数。返回布尔值

1.4 spl_autoload_call(string $class)

请求已注册类。无返回值。执行对应类的构造。

#测试文件 test1.php php 7.2 之后defined('APPPATH') or define('APPPATH', "./autoload");
defined('DS') or define('DS', DIRECTORY_SEPARATOR);class Load {public static function autoload() {$dir = APPPATH;$paths = [];if (is_dir($dir)) {$handle = opendir($dir);while (false !== ($file = readdir($handle))) {if ($file != "." && $file != "..") {$info = pathinfo($file);if ("php" == $info['extension']) {$path = $dir . DS . $file;@include_once $path;$paths[] = $path;}}}closedir($handle);}return $paths;}
}
spl_autoload_register(["Load", 'autoload'], true, true);
// $test1 = spl_autoload_call('Test1', true, true);
// $test1->run();
$list = spl_autoload_functions();
var_dump($list);
$test1 = new Test1();
$test1->run();
spl_autoload_call("Test1");
spl_autoload_unregister(["Load", 'autoload']);
$list = spl_autoload_functions();
var_dump($list);

 文件夹结构:autoload/test1.php  autoload/test2.php。

#test1.php
class Test1 {public function __construct() {echo "构造:" . __CLASS__ . PHP_EOL;}public function run() {var_dump(__CLASS__);}
}#test2.php
class Test2 {public function run() {var_dump(__CLASS__);}
}

 测试结果

array(1) {[0] =>array(2) {[0] =>string(4) "Load"[1] =>string(8) "autoload"}
}
构造:Test1
string(5) "Test1"
array(0) {
}

1.5 spl_autoload_extensions(?string $file_extensions = null)

加载并返回的默认扩展。返回字符串。

1.6 spl_autoload(string $class, ?string $file_extensions = null)

__autoload()函数的默认实现。需要传入类名,找不到对应类会报错。最好对应类设置命名空间,防止类名重复导致加载错误

测试1

set_include_path(APPPATH);
spl_autoload_extensions('.php');
spl_autoload_register();
$list = spl_autoload_functions();
var_dump($list);
$test1 = new Test1();
$test1->run();

测试结果

array(1) {[0] =>string(12) "spl_autoload"
}
构造:Test1
string(5) "Test1"

测试2

#test1.php
namespace app;
class Test1 {public function __construct() {echo "构造:" . __CLASS__ . PHP_EOL;}public function run() {var_dump(__CLASS__);}
}#test2.php
namespace app;
class Test2 {public function run() {var_dump(__CLASS__);}
}#./autoload/config.json
{"app\\Test1":"test1.php","app\\Test2":"test2.php"
}
function autoload_test3() {$config_file = APPPATH . DS . "config.json";if (!is_file($config_file)) {return false;}$config = json_decode(file_get_contents($config_file), true);foreach ($config as $key => $value) {$file = APPPATH . DS . $value;if (is_file($file)) {@include_once $file;}$classname = $key;spl_autoload($classname);}
}spl_autoload_register('autoload_test3');
$list = spl_autoload_functions();
var_dump($list);
$test1 = new app\Test2();
$test1->run();

 测试结果

array(1) {[0] =>string(14) "autoload_test3"
}
string(9) "app\Test2"

二 debug_backtrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT, int $limit = 0)

limit:用于限制返回堆栈帧的数量。默认为(limit=0),返回所有的堆栈帧。

options:

1)DEBUG_BACKTRACE_PROVIDE_OBJECT、1:object、args两个索引都包括

2)0:仅包括args索引

3)DEBUG_BACKTRACE_IGNORE_ARGS、2:两个索引都不包括

4)DEBUG_BACKTRACE_PROVIDE_OBJECT|DEBUG_BACKTRACE_IGNORE_ARGS、3:仅包括object索引

#test2.php
namespace app;
class Test2 {public function run() {var_dump(__CLASS__);}public function test($args) {var_dump(debug_backtrace());}
}

 测试

spl_autoload_register('autoload_test3');
$list = spl_autoload_functions();
$test1 = new app\Test2();
$test1->test(['qwe' => 123]);

测试结果

array(2) {[0] =>array(7) {'file' =>string(32) "D:\workspace\php\test\test11.php"'line' =>int(68)'function' =>string(4) "test"'class' =>string(9) "app\Test2"'object' =>class app\Test2#1 (0) {}'type' =>string(2) "->"'args' =>array(1) {[0] =>array(1) {'qwe' =>int(123)}}}[1] =>array(4) {'file' =>string(32) "D:\workspace\php\test\test11.php"'line' =>int(70)'function' =>string(5) "test3"'args' =>array(0) {}}
}

preg_replace_callback_array

参数1 pattern:以正则表达式为key的数组,value为匿名函数。

参数2 $subject: 需处理的字符串。字符串或数组。

参数3 $count: 替换次数

参数4 $flags:影响匹配数组的格式。值为PREG_OFFSET_CAPTURE或PREG_UNMATCHED_AS_NULL。

PREG_OFFSET_CAPTURE:匹配返回时会附加字符串偏移量。返回配置数据中包含字符串开始的位置。

PREG_UNMATCHED_AS_NULL:使用该标记,未匹配的子组会报告为 null;未使用时,报告为空的 string。

#测试
$str = '<p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5, PHP 7, PHP 8)</p>';
$pattern = ['/(?<=class=").*(?=">)/' => function ($match) {var_dump($match);return '123';},'/php+/i' => function ($match) {return "~php~";},
];
$result = preg_replace_callback_array($pattern, $str);
var_dump($result);#测试结果
string(67) "<p class="123">(~php~ 4 &gt;= 4.0.1, ~php~ 5, ~php~ 7, ~php~ 8)</p>"

四 迭代

4.1 is_iterable(mixed $value)

判断是否可迭代。返回布尔值。

4.2 iterator_count(Traversable|array $iterator))

对迭代器中的元素计数。不能保留指针位置。例如以下例子,不设置$iterator->rewind()则$iterator->valid()返回false。

使用$iterator->count()不会影响指针。

4.3 iterator_to_array(Traversable|array $iterator, bool $preserve_keys = true)

preserve_keys:是否使用迭代器元素键作为索引

$arr = ["test1", "asd", "qw"];
if (is_iterable($arr)) {$iterator = new ArrayIterator($arr);var_dump($iterator->count());var_dump(iterator_count($iterator));$iterator->rewind();while ($iterator->valid()) {$count = $iterator->count();echo "count:" . $count . PHP_EOL;$item = $iterator->current();$key = $iterator->key();$count = $iterator->count();echo "key:" . $key . " item:" . $item . " count:" . $count . PHP_EOL;$iterator->next();}$arr2 = iterator_to_array($iterator, true);var_dump($arr2);var_dump(iterator_count($iterator));
}

 测试结果

int(3)
int(3)
count:3
key:0 item:test1 count:3
count:3
key:1 item:asd count:3
count:3
key:2 item:qw count:3
array(3) {[0] =>string(5) "test1"[1] =>string(3) "asd"[2] =>string(2) "qw"
}
int(3)

五 func_get_args()

获取函数参数列表的数组。返回数组

function test6() {$numargs = func_num_args();$arg_list = func_get_args();$param = [];if (1 == $numargs) {$first = $arg_list[0];if (is_string($first)) {$param = $arg_list;}return $param;} else {$obj = new ArrayObject($arg_list);$iterator = $obj->getIterator();$use_list = [];while ($iterator->valid()) {$item = $iterator->current();if (is_numeric($item)) {$item = (string) $item;}if (is_string($item)) {$item = test6($item);}if (is_array($item)) {$use_list = array_merge($use_list, $item);}$iterator->next();}// return $use_list;var_dump($use_list);}
}test6(1, 2, 3);

 测试结果

array(3) {[0] =>string(1) "1"[1] =>string(1) "2"[2] =>string(1) "3"
}


 

http://www.khdw.cn/news/17042.html

相关文章:

  • 网络规划设计 网站建设南昌seo服务
  • 免费做请帖的网站市场营销毕业后做什么工作
  • 我们不仅仅做网站更懂得网络营销商品推广
  • 租号网站怎么做百度建站多少钱
  • 园林网站源代码seo系统培训班
  • 常德网站建设渠道家庭优化大师下载
  • 大凤号 网站建设全网媒体发布平台
  • 淘宝建设网站常见问题百度关键词价格排行榜
  • 网页托管服务是什么seo技术博客
  • node做网站优势夫唯seo培训
  • 用web开发一个网站怎么做网站内容检测
  • wordpress 4.9 正式版seo国外英文论坛
  • 外包网站开发合同范本建设网站费用
  • 做化工资讯的网站百度一下打开网页
  • 杭州亚运会闭幕式郑州网站优化哪家好
  • 非模板网站精美软文句子
  • 为客户做网站的方案上海seo博客
  • 公众号网站开发用什么模板友情链接作用
  • 山西响应式网站建设制作网站运营指标
  • web做网站访问量统计宁波pc营销型网站制作
  • 栗田工业大连有效公司网站哪年做的谷歌竞价推广教程
  • 贵州国龙翔建设有限公司网站微博营销的特点
  • 网站如何做ip签名图片企业营销策划有限公司
  • 郑州市做网站公司a汉狮搜索引擎环境优化
  • 用dreammwea怎么做视频网站宁波seo咨询
  • 东莞 营销网站建设网站要怎么创建
  • 做游戏网站的分析哈尔滨seo优化公司
  • 北京网站建设好不好天百度收录网站要多久
  • 青岛做公司网站百度用户服务中心官网
  • 中国建设建筑教育网站常德网站优化公司