草庐IT

spl-autoloader

全部标签

php - Laravel 5 如何包含 autoload.php

我正在尝试包含一个指向autoload.php的路径vendor/autoload.php试图访问它的文件在public/this-file.php我将路径设置为require_once'../vendor/autoload.php';但它只是抛出错误-Warning:require_once(../vendor/autoload.php):failedtoopenstream:NosuchfileordirectoryFatalerror:require_once():Failedopeningrequired'../vendor/autoload.php'(include_path

php - 当已经使用了spl_autoload_register时,为什么需要unserialize_callback_func?

ini_set('unserialize_callback_func','spl_autoload_call');spl_autoload_register(array(self::getInstance(),'autoload'));为什么像上面那样设置spl_autoload_call?我做了一个测试:$serialized_object='O:1:"a":1:{s:5:"value";s:3:"100";}';ini_set('unserialize_callback_func','mycallback');functionmycallback($classname){echo1

php - SPL objectstorage vs SPL 数组 vs 普通数组

普通数组、SPL数组和SPL数据存储之间的区别、*用法*场景是什么?如果有人能给出一些使用SPLarray和SPLobjectsrorage的实际例子,那就太好了。 最佳答案 SplFixedArray的主要优势是对于数组的特定用例子集,它要快得多(该子集是只有整数键和固定长度的数组)。所以,例如:$a=array("foo",$bar,7,...thousandsofvalues...,$quux);$b=\SplFixedArray::fromArray($a);//here,$bwillbemuchfastertousetha

php - PHP的spl_autoload_register是如何解决与require_once的循环依赖的?

PHP的spl_autoload_register是如何解决与require_once的循环依赖的?循环依赖可以解决一些情况,但不是全部。让我们从一个失败的例子开始。假设我们在不同的文件中定义了三个类:cat.phpclassCatextendsAnimal{}animal.phprequire_once('cat.php');classAnimalextendsCreature{}creature.phpclassCreature{}假设我们还有一个具有自动加载器并创建Animal实例的脚本:run.phpspl_autoload_register(function($classNa

php - Composer autoload_namespaces 数组是空的,但它正在下载我的包

我在Windows上使用composer,当我执行composerinstall或composerupdate.{"require":{"bcosca/fatfree":"dev-master","respect/validation":"^1.1"}}我的index.php中的第一行是require_once__DIR__.'\vendor\autoload.php';这似乎没有加载任何东西,例如,很多与未从这2个包中定义的类相关的错误。我进一步查看它,发现我的autoload_namespaces.php如下:数组完全是空的,怎么会这样呢?我希望在这里看到这两个包的要求...感谢您

php - 我无法使用 phpunit : Cannot open file "autoload.php" 进行测试

配置:PHPUNIT:4.5.0PHP:5.4.12服务器:WampComposer:版本1.0-dev2015-02-1721:55:44Composer.json:{"require-dev":{"phpunit/phpunit":"4.5.*"}}自动加载.php:registerNamespaces(array('Hangman'=>__DIR__.'/src','Symfony'=>__DIR__.'/vendor',));$loader->register();phpunit.xml:tests/Hangman/Testsvendor问题:我执行了:phpunit--boo

php - Composer autoload - 从父目录加载类

我目前正在开发一个需要从其父目录访问类的Laravel项目。Composer.json>PSR-4:"psr-4":{..."ModuleA\\":"../ModuleA/baseObjects","ModuleB\\":"../ModuleB/baseObjects"}示例文件结构:/var/www+-/xxx(project)+-/ModuleA+-/baseObjects-configClass.inc+-/ModuleB+-/baseObjects-configClass.inc+-/laravel-composer.json我运行composerdump-autoload但项

PHP 使用 SPL 迭代器递归删除空目录

我正在为如何使用SPL迭代器删除PHP中的空目录树而苦恼。考虑以下目录结构,其中所有目录都是空的:/topdirlevel1level2我试过以下方法:$it=newRecursiveIteratorIterator(newRecursiveDirectoryIterator('/topdir',RecursiveIteratorIterator::CHILD_FIRST));foreach($itas$file){if($file->isDir()){rmdir((string)$file);}}但是RecursiveIteratorIterator::CHILD_FIRST阻止了底

PHP 的 SPL : Do its interfaces involving arrays cover all array properties?

是否可以通过实现所有必要的SPL接口(interface)来编写一个与实际PHP数组几乎没有区别的类?他们是否遗漏了任何重要的东西?我想构建一个更高级的Array对象,但我想确保如果我用自定义Array类替换它们,我不会破坏到处使用数组的现有应用程序。 最佳答案 我能想到的唯一问题是gettype()和is_array()函数。检查你的代码gettype($FakeArray)=='array'is_array($FakeArray)因为虽然你可以像数组一样使用对象,但它仍然会被识别为一个对象。

php - 脚本@php artisan package :discover handling the post-autoload-dump event returned with error code 255

我把我的项目从办公table搬到了另一个办公table。当我运行phpartisan时,它不起作用。我尝试运行composerupdate,但它返回错误Script@phpartisanpackage:discoverhandlingthepost-autoload-dumpeventreturnedwitherrorcode255 最佳答案 这就是我在从Laravel版本6.x-7.x升级后解决这个问题的方法:在App\Exceptions\Handler中更改//UseException;UseThrowable;然后方法接受T