Stichoza / google-translate-php

🔤 Free Google Translate API PHP Package. Translates totally free of charge.
MIT License
1.79k stars 380 forks source link

Class "Stichoza\GoogleTranslate\GoogleTranslate" not found #190

Closed Open-AGI closed 1 year ago

Open-AGI commented 1 year ago
┌──(root㉿agir)-[/var/www/html]
└─# composer require stichoza/google-translate-php
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Info from https://repo.packagist.org: #StandWithUkraine
./composer.json has been updated
Running composer update stichoza/google-translate-php
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
5 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found
Using version ^5.1 for stichoza/google-translate-php

┌──(root㉿agir)-[/var/www/html]
└─# php demo.php                                  
Hello World!PHP Fatal error:  Uncaught Error: Class "Stichoza\GoogleTranslate\GoogleTranslate" not found in /var/www/html/demo.php:9
Stack trace:
#0 {main}
  thrown in /var/www/html/demo.php on line 9

┌──(root㉿agir)-[/var/www/html]
└─# php -v      
PHP 8.2.4 (cli) (built: Mar 16 2023 14:24:40) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.4, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.4, Copyright (c), by Zend Technologies

┌──(root㉿agir)-[/var/www/html]
└─# uname -a
Linux agir 6.0.0-kali3-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.0.7-1kali1 (2022-11-07) x86_64 GNU/Linux

┌──(root㉿agir)-[/var/www/html]
└─# 

my demo.php:

<?php

echo "Hello World!";

use Stichoza\GoogleTranslate\GoogleTranslate;

$tr = new GoogleTranslate('en'); // Translates into English

Thank you very much for any helps

Stichoza commented 1 year ago

You forgot to require the vendor/autoload.php file for class autoloading. Most of the frameworks do that automatically, but since your demo.php is a standalone file, you'll have to manually require "vendor/autoload.php";