Class not found after "require_once" - php

I get the following error:
`Fatal error: Class 'DummyClass' not found in...`
<?php
require_once("3rdparty/simplesaml/lib/_autoload.php");
class login extends DummyClass { (this is the line the error refers to)
[...]
}
?>
If I comment out the require_once it works perfectly fine.
DummyClass is defined externally and can be found in the prepend-file. (I don't think it matters for this problem as it works as expected if I comment out require_once)
The path to the file should also be correct as it gives me a "Failed opening required..." Error if I change the path.
I also tried switching between PHP 5.6 and 7 - no difference.
So, I would like to ask you for help. Do you have any hints / ideas, why I might get that error?

Problem solved.
The old framework was using the old __autoload function, which is deprecated.
SimpleSAMLPHP used the new function. Those autoload-combinations cause one of them to override the other.
Solution:
Switch from __autoload to spl_autoload_register.
Similar Question: Override vendor autoload composer

Related

Drupal 8 not adding my module class to the registry / autoloading

I'm having trouble getting Drupal 8 to load my custom module's classes from the same namespace. Here's what I've got:
<?php
namespace Drupal\sign_up\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
// ... snip ...
class StandardForm extends CLESignUpForm
{
Which all works perfectly well on my local environment. When deployed the server says: PHP Fatal error: Class 'Drupal\sign_up\Form\CLESignUpForm' not found in /path/to/drupal/modules/sign_up/src/Form/StandardForm.php on line 21
If I add the line:
include 'CLESignupForm.php';
It works just fine. But that defeats the purpose of auto-loading classes, doesn't it? get_declared_classes() does not show my base class .. or even the currently loaded class for that matter.
Any thoughts on how to make this particular environment comply? I've already loaded the db and config directly from my local setup where it's working. Could it be a php / apache setting somehow?
Turns out I'm a knucklehead. CLESignUpForm is the incorrect capitalization of the type. The correct capitalization is CLESignupForm. Still not clear why it works in every other environment and not this one, but it makes me feel like there's a bit more sanity at least.

Fatal error: Class 'Stripe' not found in C:\wamp\www\

I'm getting an error that class is not found, but I clearly have the right path for where it is located:
<?php
require_once('stripe-php-2.1.0/stripe/lib/Stripe.php');
Stripe::setApiKey('my_key');
var_dump($_POST['stripe-token']);
?>
Every article I've come across all claim that the problem is (not including the right path) in the require_one, include, or require. (I've tried all 3). But still no luck. My database calls follow the same format and my WAMP server has no problem creating my database class.
This is copied directly from my file explore (copy paste)
website\stripe-php-2.1.0\stripe\lib\Stripe.php
My php file that I am using to try and access Stripe sits in the same place as 'website'.
PHP version 5.5.12
tutorial references: http://www.larryullman.com/2013/01/09/writing-the-php-code-to-process-payments-with-stripe/
Other reference: http://www.youtube.com/watch?v=Lka_JBM9bbY
It's because it uses a namespace. Try:
\Stripe\Stripe::setApiKey('my_key');
It is better to initialize all classes.
require_once ("stripe_folder/init.php");
then use namespaces:
\Stripe\Stripe::setApiKey('key_key_key_key_key_key');

Cannot use X as Y because the name is already in use, even though it's not

I'm using PHP 5.4, and have a PSR-0 class structure similar to the following.
A\Library\Session.php:
namespace A\Library;
class Session { ... }
My\Application\Session.php:
namespace My\Application;
class Session { ... }
My\Application\Facebook.php:
namespace My\Application;
use A\Library\Session;
class Facebook { ... }
When I try to run the application, I get the following error:
Cannot use A\Library\Session as Session because the name is already in use in My\Application\Facebook.php
Even though it's not, at least not in this file. The Facebook.php file declares only the Facebook class, and imports exactly one Session class, the A\Library one.
The only problem I can see is that another Session class exists in the same namespace as the Facebook class, but as it was never imported in the Facebook.php file, I thought it did not matter at all.
Am I wrong (in that case please point to the relevant documentation), or is this a bug?
There is a bug confirmed in PHP that may affect the behavior you see. It is supposed to fatal error, but with opcache enabled, it may still execute flawlessly.
https://bugs.php.net/bug.php?id=66773
If it still concerns you, please vote for the bug.
No, this is not a bug. As mentioned in Using namespaces: Aliasing/Importing
use A\Library\Session;
is the same as:
use A\Library\Session as Session;
So try using something like:
use A\Library\Session as AnotherSessionClassName;
The only problem I can see is that another Session class exists in the
same namespace as the Facebook class, but as it was never imported in
the Facebook.php file, I thought it did not matter at all.
Yes, it does matter. This is why you don't need to "import" classes from the same namespace. If you have conflicting names from different namespaces, you need to alias the class.
namespace My\Application;
use A\Library\Session as ASession; // choose a proper alias name here
class Facebook { ... }
I've read the thread about the issue, but I tested on many PHP versions (php 5.5, 5.6, 7.*, x32, x64, vc11, vc14, vc5). I'm using Laravel with Laragon. But, when I build up the server with php artisan serve (and open the server at http://localhost:8000) I have the problem of "the namespace that some Class was already used" and stuff.
I tested with and without opcache extension and nothing works, then I tested the virtual domain that Laragon provides and... voila, the error just disappeared and now I can work OK. I don't know what was happening, my namespaces were OK, I had an alias but the same code works in many machine without problem (AWS, local, prod, dev, etc) but only in my machine I had the problem just as I described it.
So, if someone is working with Laravel (5.1) and is having this issue, try the virtual host of Laragon.

Fatal error: Call to undefined function: MDB2_Driver_MYSQL::getAll()

I am upgrading a site from Fedora 14, PHP4, and PEAR DB to Fedora 16, PHP 5.4 and PEAR MDB2 2.5.0b3, and I am getting the error
Fatal error: Call to undefined function: MDB2_Driver_MYSQL::getAll(). in /usr/share/php/MDB2.php on line 1892
Obviously, I've checked line 1892 of the MDB2.php file, and it contains the error reporting code for the __call magic method (allows you to call a specific function by passing it into __call)
I have checked for usages of __call, and there don't seem to be any. Likewise, when I try to find where MDB2_Driver_MYSQL is coming from, the only place it is even mentioned is in MDB2.php (as a comment about the driver for MySQL), in the class declaration (class MDB2_Driver_mysql extends MDB2_Driver_Common), and the description title in the .xml file.
I have manually included the /usr/share/php/MDB2/Extended.php file in the file where the MDB2_Driver_mysql class is defined, and that didn't help (not that this would have been a permanant fix...)
Has anyone encountered this error, and if so, what did you do to fix it? Google has proved nearly useless, as the only place it is specifically mentioned doesn't really deal with fixing it.
change getAll() in your class, to queryAll(), cause there some difference between DB & MDB2, and the same with getOne, getRow - they all changed to queryOne, queryRow. Here you can read about it http://www.phpied.com/db-2-mdb2/
Make sure you load the extended module in your code prior to making a query, similar to below:
$db->loadModule('Extended');

Can no longer install WordPress on MAMP- "Fatal error: Cannot redeclare class wpdb"

I've been developing WordPress sites for a long time on my local MAMP server. Now all of a sudden, it won't let me create any new sites. Whenever I set up a new one, instead of running the install script I get:
Fatal error: Cannot redeclare class
wpdb in
/Applications/MAMP/htdocs/[my_site]/wp-includes/wp-db.php
on line 52
This happens with all WordPress versions. I cannot thing of anything that would have caused this. I've done everything short of re-install MAMP. Does anyone have any ideas? I'm desperate at this point..
Check out the include path for php. It's likely that a second instance of wordpress is on the include path and is therefore conflicting with the one you're trying to load. It's also possible that a different package on the include path has a class called wpdb and is therefore causing a conflict.
wpdb is being created again some where, if this happened all of a sudden i suggest that you disable any plugins you've recently added. Or even better do a global find for the term class wpdb and see if that appears within more than 1 file. Also, check your functions.php file for a loop that might be loading wp-db.php more than once.
A workaround fix is to wrap the wpdp class in wp-includes/wp-db.php in the following:
Line 52:
if(class_exists('wpdb') != true)
{
class wpdb {
...
}
}
This solved the install issue- You could probably remove it after that, although it can't hurt to leave it I guess.
Still don't understand why this problem has popped up- If someone has an explanation I'd be eager to hear it.

Categories