autoload

PHP composer autoload not loading class

浪子不回头ぞ 提交于 2020-01-24 08:41:26
问题 I'm just getting started using composer for dependency management and I'm having a hard time figuring out how I'm not adhering to psr-4 for autoloading so I'm here for advice. I've got a class that generates random values that is already on the packagist. The project structure is the following (I've labeled the composer.json files A and B): project dir |classfile.php A |composer.json |vendor |autoload.php |ejfrancis |php-random-value B |composer.json |RandomValue.php <--the class I want

Conflict between Codeigniter AUtoload and Flourish Autoload functions

余生长醉 提交于 2020-01-23 03:37:05
问题 I am developing a web application, using the Codeigniter ( http://codeigniter.com/ ) framework plus the Flourish library ( unframework ) ( http://flourishlib.com/ ). I simply dropped the flourish folder into my application, then I created a flourish initialization and config files as instructed (these create the Flourish autoload). This is my folder structure: ---auxcode\ --------init.php --------config.php --------flourish\ ---system\ ---application\ ---public_html\ The init file ONLY

PHP autoload namespace

淺唱寂寞╮ 提交于 2020-01-15 05:54:19
问题 I want to autoload my classes putting only the namespace + the filename. Example: directories skeleton: \var\www |_ foo | |_ A.php | |_ B.php | |_ index.php A.php: <?php namespace foo\A; class A { private $a; public function __construct($a) { $this->a = $a; } } B.php: <?php namespace foo\B; use foo\A; class B extends A { private $b; public function __construct($a, $b) { parent::__construct($a); $this->b = $b; } } index.php: <?php use foo\B; define('ROOT', __DIR__ . DIRECTORY_SEPARATOR); $b =

PHP namespace and dynamic classname

左心房为你撑大大i 提交于 2020-01-14 13:49:47
问题 I've encountered a "weird" thing while experimenting with spl_autoload, namespaces and dynamic class names. I use PHP 5.3.2, call the autoload like this set_include_path(get_include_path().PATH_SEPARATOR."classes".PATH_SEPARATOR."utils"); spl_autoload_extensions(".class.php"); spl_autoload_register(); Now to the core. Suggest following code: new \User\Student; $name="\User\Student"; new $name(); This works fine, file classes/user/student.class.php gets loaded successfully, both constructions

PHP namespace and dynamic classname

ⅰ亾dé卋堺 提交于 2020-01-14 13:49:28
问题 I've encountered a "weird" thing while experimenting with spl_autoload, namespaces and dynamic class names. I use PHP 5.3.2, call the autoload like this set_include_path(get_include_path().PATH_SEPARATOR."classes".PATH_SEPARATOR."utils"); spl_autoload_extensions(".class.php"); spl_autoload_register(); Now to the core. Suggest following code: new \User\Student; $name="\User\Student"; new $name(); This works fine, file classes/user/student.class.php gets loaded successfully, both constructions

Auto-load function / class libraries when needed

删除回忆录丶 提交于 2020-01-14 12:48:13
问题 First, a little background. The company I work for uses a massive function / class library, which gets included on every single page. Thousands and thousands of lines of functions, 90% of which probably won't even be called on a page. In an attempt to lighten the server load a little, I've been experimenting with smarter library setups. To this end, I've split the entire file into categorized library files (i.e. sql.functions.php, date.functions.php, and others.) Unfortunately, including

PHP namespacing and spl_autoload_register

谁都会走 提交于 2020-01-14 07:57:10
问题 I had spl_autoload_register working fine but then I decided to add some namespacing to bring in PSR2 compliance and can't seem to get it working. Directory strcuture: -index.php -classes/ -Class1.class.php -Class2.class.php -Class3.class.php Each class starts with: namespace Foo; Class ClassX { Index.php: <?php spl_autoload_register(function($class) { include 'classes/' . $class . '.class.php'; }); $myObj = new Class1(); echo $myObj->doSomething(); This products an error Fatal error: Class

__autoload fails to throw an Exception when it fails to load a class on a static method call

不羁的心 提交于 2020-01-14 03:59:08
问题 While attempting to implement some kind of error handling when my __autoload() function fails to load a file I stumbled upon this little 'oddity'. According to http://nl.php.net/autoload Exceptions thrown from within the __autoload() function can be caught in a catch block since PHP version 5.3+. Note: Prior to 5.3.0, exceptions thrown in the __autoload function could not be caught in the catch block and would result in a fatal error. From 5.3.0+ exceptions thrown in the __autoload function

PHP trying to use autoload function to find PDO class

烂漫一生 提交于 2020-01-13 09:49:06
问题 This has been bugging me for some time now and I can't seem to make sense of it. My phpinfo reports that PDO is installed and I can connect to my database on my index.php file. But when I try to open a PDO connection on a namespaced class, php is trying to use my autoload function to find PDO.php which won't work. My class is as follows: abstract class { protected $DB; public function __construct() { try { $this->DB = new PDO("mysql:host=$host;port=$port;dbname=$dbname", $user, $pass); }

Getting a fatal error when autoloading a PHP class

谁说我不能喝 提交于 2020-01-11 12:15:13
问题 I am attempting to use Cartalyst, a comprehensive PHP Library for Stripe payments. Here is a link to their documentation: https://cartalyst.com/manual/stripe/1.0. Here is the code I am trying to get to work: $stripe = Stripe::make('your-stripe-api-key'); $customers = $stripe->customers()->all(); foreach ($customers['data'] as $customer) { var_dump($customer['email']); } When I run the code above (in my real code I have my api inserted), I receive the following error: Fatal error: Class