FAQ Database Discussion Community


php spl_autoload_register() doesn't load a class

php,class,domdocument,autoload,spl-autoload-register
I have an index.php that require Test1 class trough spl_autoload_register(). In the Test1 class the Test2 class is required with the same autoload but this error occurred: Fatal error: DOMDocument::registerNodeClass(): Class Test2 does not exist in... I tried to see if the autoload work writing $test2 = new Test2(); and...

How to I use Composer to autoload classes from outside the vendor?

php,composer-php,autoload
I use psr-4 autoloader from composer: "autoload": { "psr-4": { "DG\\Munchkin\\": "src/DG/Munch/" } } This loads classes from /var/www/html/xxx/vendor/yyy/src/DG/Munch But how can I load classes from /var/www/html/xxx/? I wrote my own autoloader, but when I require vendor/autoload.php (composer autoload) and my autoloader, it won't work until I create instance of...

PHP Auto-execute script upon any page load

php,require,autoload
My Index.php namespace Toplist; require_once "Helper/Functions.php"; use Toplist\Helper\Functions; use Toplist\Controller\IndexController; use Toplist\Model\IndexModel; use Toplist\View\IndexView; My Functions.php function __construct() { spl_autoload_register('self::l'); } public static function l($c) { $n = $c . '.php'; $f = preg_replace('/Toplist\\\\/', '', $n); $f = preg_replace('/\\\\/', '/', $f); if(!file_exists($f)) { return false; } require_once $f; } This...

PHP Composer: Setting dynamic variable paths in the autoload function

php,composer-php,autoload
I have recently started using composer to autoload my classes. But I find I have to upload each directory individually as I store an src/ directory and a tests/ directory foreach class. For example: "Core\\Router\\": "system/Core/Router/src/", "Core\\Router\\Tests\\": "system/Core/Router/tests/", "Core\\DatabaseManager\\": "system/Core/DatabaseManager/src/", "Core\\DatabaseManager\\Tests\\": "system/Core/DatabaseManager/tests/" Is there a way to make it so...

Composer Autoload Issue

php,class,include,composer-php,autoload
I've added composer to an existing project that uses the PHP autoload function. Now that composer autoload.php is being used I've removed my old autoload function and I'm trying to load my existing source directory via composer autoload but it isn't picking up any of my existing source classes. Everything...

I can't use Autoloader from Symfony2 in Symfony 1.4 for load this namespaced classes

namespaces,classloader,symfony-1.4,autoload
I want to use this php library with namespaced classes in my Symfony 1.4 project: https://github.com/donquixote/cellbrush. I'm not quite familiar with the namespaces concept. So when i fisrt try the to use the main class of this library, according to its docs, i just did: $table = \Donquixote\Cellbrush\Table\Table::create(); And i...

Silex namespace : class MainController does not exist

php,class,namespaces,autoload,silex
I try to use Silex Framework, but i have a problem with namespaces I think. when I instanciate my class MainController i have the following error : Class "MainController" does not exist here the namespace declaration in my MainController.php : namespace App\Controllers; use Silex\Application; class MainController implements \Silex\ControllerProviderInterface { .......

Deleting migrations results in an Exception

php,laravel,laravel-5,composer-php,autoload
In my Application, when I run php artisan migrate:make create_location_user_table, then delete the generated file (doesn't matter if I delete the line created in vendor/composer/autoload_classmap.php, the php artisan migrate:refresh command throws an error: include(<path_to_project>/database/migrations/2015_06_21_105357_create_location_user_table.php): failed to open stream: No such file or directory After running commands to get rid of...

Bootstrap of Zend Module is not loading

php,zend-framework,autoload
I am new in working with zend so I am facing this problem from the past two days. I have searched a lot but still can not find any solution. Possible duplicate of Zend Module Bootstrap does not load but it still can not solve my problem. In my User...

Laravel 5 - constantly repeating use statements

php,namespaces,laravel-5,autoload
Is there a central place where I can put 'use' statements so I don't have to keep doing things like this with every single controller I create? <?php namespace App/Http/Controllers use Session; use Auth; use Input; use Log; use Carbon; use Response; use Illuminate\Routing\Controller; class BlaBlaController extends Controller {} Just...

One shared vendor with two projects

php,symfony2,composer-php,autoload,vendor
I'm working on 2 applications right now. The first one is a CMS, and the second is a shop. I want to move my vendor one level above and the share it between projects. So my structure will be something like this: project1/ project2/ shared_vendor/ I read about this. I...

Access to composer autoloaded files in laravel 5

laravel,instance,bind,autoload
Trying to use a non-Laravel package: https://packagist.org/packages/luceos/on-app Edited composer.json to require it and did the composer install, update, then dump-autoload -o. This package requires an initialization: vendor/luceos/on-app/src/OnAppInit.php Which isn't a class and only has the one method. But it doesn't seem to be loaded when I try to bind it...

Using Composer's autoloader with personal code

php,composer-php,autoload,spl-autoload-register
I'm building a small project using Composer, but I now have to use some custom code, in the parent folder of vendor folder. Similar file structure: libraries > companyname > namespace > classfile.php Is it possible to effectively use the composer autoloader? It seems that it is, but I'm having...

Hook variable call in PHP

php,autoload,magic-methods
what i'm trying to archive is kind of an autoloader for variables in php. is there any way to hook the loading of variables in php? example usage would be: function __autoloadVar($varname,$indices){ global $$varname; if(count($indices) > 0 && !isset($$varname[$indices[0]])){ //first index $$varname[$indices[0]] = load_var_content($indices[0]); //this would call a function that...

Laravel, autoload classes based on an input array of class names

laravel,autoload
I have various classes, e.g. <?php namespace MyApp\Notifications; class FirstNotification implements NotificationInterface { public function getMessage() { return 'first message'; } } and <?php namespace MyApp\Notifications; class SecondNotification implements NotificationInterface { public function getMessage() { return 'second message'; } } I then have an array like: ['First','Second']. I'm using: foreach...

Composer file is set up wrong? Not Auto loading my class - PHP

php,composer-php,autoload
In the above image you can see my composer.json. This file belongs to Freya/Loader/Assets, which you can see is expanded. You can also see the vendor directory is created and that I have a phpunit.xml file which looks as such: <phpunit bootstrap="bootstrap.php" backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" > <testsuites>...

laravel 5 autoload not loading models

composer-php,autoload,laravel-5
I have this composer config: under classmap: "app/models" under psr-4: "App\\Models\\": "app/models" "autoload": { "classmap": [ "database", "app/models" ], "psr-4": { "App\\": "app/", "App\\Models\\": "app/models" } }, "autoload-dev": { "classmap": [ "tests/TestCase.php" ] }, Here is my model: namespace App\Models; class TemplateRow extends Model{ protected $table = "template_rows"; } in...

Issue with Composer's Autoloader

php,composer-php,autoload
I'm starting work on a new mini-framework project, which I have in a local GIT repo on my machine. I've set up a test project that pulls in the local repo via Composer, however the autoloader isn't working as expected (Fatal Error: Class X not found errors). This is the...

Swift Mailer ruins autolading

php,autoload,swiftmailer,autoloader
I'm writing simple PHP application which is using Swift Mailer library. My app doesn't use namespaces nor composer. However, after requiring swift_required.php my (model) classes are not found (Fatal error: Class 'Format' not found is thrown by PHP interpret). Autolading define("_DOCUMENT_ROOT", str_replace("//", "/", $_SERVER['DOCUMENT_ROOT'] . "/")); function __autoload($class_name) { $file_name...

Composer dump-autoload gives preg_match error

php,composer-php,autoload
I have Composer in my PHP project installed, and want to use the autoloader. On this page I read how the composer.json file should look like and that I should run the command dump-autoload. My composer.json file looks as follows { "require-dev":{ "phpunit/phpunit":"4.5.*", "autoload":{ "psr-0":{ "Yii\\":"yii-1.1.14.f0fee9/" } } } }...

Priority between spl_autoload_register and extension's function?

php,autoload,php-extension
I use composer to manage my dependencies and class loading. This tool uses spl_autoload_register function. I would like to use a PHP's extension that provides some classes with same definition (name, namespacing, functionnalities) than others classes defined throught composer. Which class will PHP load? The extension's one, or the autoload's...