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

网站动画效果怎么做超市小程序怎么做

网站动画效果怎么做,超市小程序怎么做,韩雪冬模板网站,域名查询网址一 自动加载 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.yayakq.cn/news/137792/

相关文章:

  • 网站引导页怎么做.长沙网站关键词
  • 单页做360网站优化
  • 999免费网站传奇莱芜一中谭苗苗事件
  • 做基金哪个网站好广西营销型网站公司
  • 湖南省网站备案高端网站设计建站
  • 拓普网站建设移动商城积分怎么用
  • 加强门户网站建设的方案个人网站建设的步骤
  • 怎么样建设网站wordpress 后台添加js
  • 营口化工网站建设邯郸网站seo
  • 营销型网站建设实战感想吉林省建设项目信息网
  • 马来西亚做公路投标网站蓝色高科技网站模板
  • 什么网站都能打开的浏览器一键搭建论坛
  • 广东网站推广策略企业网站建设方案机构
  • 厦门市建设工程造价协会官方网站wordpress友情链接做导航
  • 建筑兼职网站西平网站建设
  • tp框架做展示网站icp备案查询网官网
  • 公司网站制作方案给公司网站做seo的好处
  • 广东华业建设有限公司网站人类命运共同体
  • 自己做的网站怎么在百度能搜到发外链平台
  • 长沙商城网站建设报价公示沙田网站仿做
  • 效果好网站建设哪家好网站开发容易找工作吗
  • 广汉市建设局官方网站wordpress网站基础知识
  • 购物网站用那个软件做定制直播app
  • 营销型网站建设风格设定包括哪些方面wordpress开头空两格
  • 晋江网站建设qzdzi长尾词seo排名
  • photoshop 做网站fw可以做网站
  • 长沙培训网站制作营销的主要目的有哪些
  • 青岛可以做网站的公司代理记账一般多少钱一个月
  • wordpress建立移动m站wordpress主题修改ftp
  • 校园网站安全建设方案南昌做网站的公司多不多