client icon indicating copy to clipboard operation
client copied to clipboard

Potential Naming Collision:Geminiclass in global namespace can cause conflicts

Open hohmitsu-prog opened this issue 4 months ago • 4 comments

I'm not used to English so I apologize if there are any inappropriate expressions.

There appears to be a potential naming conflict with the Gemini class defined in src/Gemini.php. This file is currently missing a namespace declaration. As a result, the Gemini class is declared in the global namespace. This can lead to conflicts in applications where Gemini might be used as a namespace for other classes, potentially causing a fatal error: Cannot declare class Gemini, because the name is already in use. While this might not be a bug in all environments, it deviates from the common PSR-4 namespacing convention and can make the library difficult to integrate into larger projects. To illustrate the potential problem Install the library via Composer. In a project, create a file that uses the Gemini namespace for another purpose before vendor/autoload.php is fully processed for all classes. An attempt to then use \Gemini\Gemini::client() can trigger a fatal error because the name Gemini is already claimed as a namespace. Suggested Solution The issue can be easily resolved by adding namespace Gemini; to the top of the src/Gemini.php file. This would align it with the other classes in the library, such as Gemini\Client and Gemini\Factory. src/Gemini.php (current): code PHP <?php declare(strict_types=1);

use Gemini\Client; use Gemini\Factory;

final class Gemini { // ... } src/Gemini.php (suggested change): code PHP <?php declare(strict_types=1);

namespace Gemini; // <-- Add this line

use Gemini\Client; use Gemini\Factory;

final class Gemini { // ... } This change would make the library more robust and prevent potential integration issues in the future. Thank you for your consideration and for maintaining this great library

hohmitsu-prog avatar Sep 12 '25 00:09 hohmitsu-prog

Yes, I have an issue and get the following error:

Fatal error: Cannot declare class Gemini, because the name is already in use in C:\xampp\htdocs\armsbox\vendor\google-gemini-php\client\src\Gemini.php on line 8

I've tried adding an alias, but it doesn't work.

use Gemini\Data\GenerationConfig;
use Gemini\Data\UploadedFile;
use Gemini\Enums\MimeType;
use Gemini\Enums\ResponseMimeType;
use Gemini\Gemini as GeminiClient; // <-- THIS LINE RESOLVES THE CONFLICT
use GuzzleHttp\Client as GuzzleHttpClient;

andrebruton avatar Oct 03 '25 13:10 andrebruton

I agree that we should add a namespace, but that will require a major version as it is a breaking change.

I'm wondering, what other Gemini class you have that causes this issue?

Plytas avatar Oct 07 '25 08:10 Plytas

Thank you for this.

I encountered the same issue.

I have just add the line [namespace Gemini;] and the conflict stopped.

Yet to see if/how that affects other functionalities though.

preciousfocus avatar Oct 11 '25 22:10 preciousfocus

What other Gemini classes do you have? Can't the name of this class be changed? Even if a namespace is added, the wrong class could still be imported due to a typo. Actually, the namespace was not defined to prevent this.

aydinfatih avatar Nov 22 '25 16:11 aydinfatih