( ! ) Fatal error: Cannot redeclare class Google_OAuth2 - php

I want sign up with google plus in codeigniter. I have include files which are required for the php script but I'm getting error
(( ! ) Fatal error: Cannot redeclare class Google_OAuth2 in
D:\wamp\www\Surecash_back\application\libraries\google-plus-api-client-master\src\auth\Google_OAuth2.php
on line 453)

The error message tells you a very simple thing:
You are trying to load\include the same class file more then once
(which results in re-declaring a class name of an already declared class).
The fastest way to check this, will be:
If you are using an autoloader - check your autoloader folder tree for the existance of a file named Google_OAuth2.php
Run a project-wide (all files in your project) search for the string "Google_OAuth2.php" and another search for "class Google_OAuth2", look for any duplicate include(), include_once() or require_once().
(in phpStorm you click Cmd+Shift+F to open the path search, and in the options tab select "Whole project" in Scope.)
See where and if you are including\requiring\autoloading the Google_OAuth2 class file more then one time.
Finally, remove the duplicate.
Hope it helps a bit!

Related

Fatal error: Uncaught Error: Class 'INFOCUS_THEME\Inc\Menus' not found

I am trying to follow a WordPress tutorial by Imran Sayed - Codeytek Academy (https://www.youtube.com/watch?v=lNtw4yxEydM&list=PLD8nQCAhR3tT3ehpyOpoYeUj3KHDEVK9h) to allow wordpress to build a menu and then inject into the html. I have followed the turorials 22, 23 and 24 (from the playlist) trying to use this in my own project.
I have copied the code and folder/file structure and added in the class, helpers, singletons and autoloaders. BUT everytime I try and run the code i get
Fatal error: Uncaught Error: Class 'INFOCUS_THEME\Inc\Menus' not found in /home/will/Local Sites/karenkeyinfocus/app/public/wp-content/themes/infocus/template-parts/header/nav.php on line 13
Error: Class 'INFOCUS_THEME\Inc\Menus' not found in /home/will/Local Sites/karenkeyinfocus/app/public/wp-content/themes/infocus/template-parts/header/nav.php on line 13
I have changed the text domain from aquila to infocus as thats whats in my project in all the locations. BUT i am completly stuck and can't work out why my code is not running.
Think this is the code thats causing the problems as it can't find the class 'INFOCUS_THEME\Inc\Menus'
<?php
$menu_class = \INFOCUS_THEME\Inc\Menus::get_instance();
$header_menu_id = $menu_class->get_menu_id( 'infocus-header-menu' );
$header_menus = wp_get_nav_menu_items( $header_menu_id );
?>
I have uploaded it to my github account and post the link here, as I thought that is the best way.
https://github.com/wkey1980/infocus
When declaring a variable as a class you must use 'new' to initiate the class.
$menu_class = new \INFOCUS_THEME\Inc\Menus();
//and then you can do
$menu_instance = $menu_class->get_instance();

How is it possible for the application to throw a redeclaration error on deleted and unexisting function?

I declared getLesediSimilarPropertyOnShow() function. When I run the application, I get this error below:
Fatal error: Cannot redeclare
GautengPropertyDB::getLesediSimilarPropertyOnShow() in
C:\xampp\htdocs\workspace\ajax-live-search\libs\GautengPropertyDB.php on line 4704
I deleted this entire function thinking about the duplication.
But when I tried to check if the function getLesediSimilarPropertyOnShow() exists by pressing CTRL+F, The Find and Replace Dialog Box displays Not Found in the current document. Meaning the function does not exist. But when I tried to reload the page, the same message persits and the line 4704 is located on comment lines outside of all functions that has nothing to do with the code. I thought may be it was previous error loaded in the cache memory and I cleaned the cache but the same error stands still. But the function does not exist in the file. I don't understand this phenomenon. Can someone please explain this?
At first use IDE like PHPStorm, that show for you where function declared.
Use http://php.net/manual/en/function.function-exists.php for check if function already declared

Jomsocial error - Notice: JFactory::getUser(): The script tried to execute a method or access a property of an incomplete object

Im getting 2 errors. I saw that Jomsocial had the problem with their own site and fixed it but never posted how. Happens when you go to post an update in jomsocial and it locks up. You refresh the page and get
Error
Sorry, User ID not found.
with the following errors. Then you go login and check the profile and the update was posted fine.
Notice: JFactory::getUser(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CUser" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /home/xxxxxxx/public_html/libraries/joomla/factory.php on line 244
Notice: CUser::CUser(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CUser" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /home/xxxxxx/public_html/components/com_community/libraries/user.php on line 52
What version of JomSocial do you use? This issue shouldn't happen

Zend_forward error Cannot redeclare class Bootstrap

When I call (in my AdminController) the _forward function, i get this error
Fatal error: Cannot redeclare class Admin_Boot in /www/application/modules/admin/Boot.php on line 33
Actually, my website's structure is:
#Application/
|--Bootstrap.php
|--#modules
|----#admin
|------Boot.php
|------#controllers
|------#view
|----#default
|------Boot.php
|------#controllers
|------#view
(I have not placed everything, but the most important is here)
So, if I call the admin module, I'm gonna call Bootstrap.php, and after, Admin_Boot.php ...
All it's ok, it's just the _forward function who cause me some trouble ...
I need help
If you are using Zend_Loader::loadFile(), think to set the third argument to TRUE;
Zend_Loader::loadFile("Boot.php", $dirs, true);

Go around cannot redeclare error in PHP

I am trying to integrate WordPress and MyBB forums. Specifically, I just want to add WordPress's navbar (the new menu) to my MyBB website. Following the CODEX example, I've added the following to my header.php of my MyBB installation:
require('/home/linuxdis/public_html/wp-blog-header.php');
However, I get 500 error when navigating to the forum. Examining error_log revealed this:
PHP Fatal error: Cannot redeclare is_super_admin() (previously declared in /home/linuxdis/public_html/forum/inc/functions.php:5484) in /home/linuxdis/public_html/wp-includes/capabilities.php on line 1213
Bummer, the functions are named the same. Other than renaming one of the functions and probably breaking absolutely everything, is there a way to go around this? :/
User require_once() instead of require() and it will make sure it will only include that file once per page.
Although not ideal in this case, you could wrap each function in a function_exists() check:
if(!function_exists('myfunc') {
function myfunc() {....}
}
This might be your only option if there are direct clashes with WP/MyBB, you're stuck if they both need is_super_admin() though.

Categories