function ClassFBLogin($d){
require_once('Facebook/autoload.php');
require_once('Facebook/FacebookSession.php');
require_once('Facebook/FacebookRedirectLoginHelper.php');
require_once('Facebook/FacebookRequest.php');
require_once('Facebook/FacebookResponse.php');
require_once('Facebook/FacebookSDKException.php');
require_once('Facebook/FacebookRequestException.php');
require_once('Facebook/FacebookAuthorizationException.php');
require_once('Facebook/GraphObject.php');
require_once('Facebook/HttpClients/FacebookCurl.php');
require_once('Facebook/HttpClients/FacebookHttpable.php');
require_once('Facebook/HttpClients/FacebookCurlHttpClient.php');
require_once('Facebook/Entities/AccessToken.php');
require_once('Facebook/GraphUser.php');
require_once('Facebook/GraphSessionInfo.php');
require_once('Facebook/HttpClients/FacebookGuzzleHttpClient.php');
require_once('Facebook/HttpClients/FacebookStream.php');
require_once('Facebook/HttpClients/FacebookStreamHttpClient.php');
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\HttpClients\FacebookCurl;
use Facebook\HttpClients\FacebookHttpable;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\Entities\AccessToken;
use Facebook\GraphUser;
use Facebook\GraphSessionInfo;
$this->a = $data;
}
when i run this program without class it works very fine but when i put all these codes inside a class i get following error:
syntax error, unexpected 'use' (T_USE)
is there any other way of calling "use" for a class? please help.
PHP: Using namespaces: Aliasing/Importing - Manual:
Scoping rules for importing
The use keyword must be declared in the outermost scope of a file (the global scope) or inside namespace declarations. This is because the importing is done at compile time and not runtime, so it cannot be block scoped.
Related
How i can remove the error so i don't have to add file tag before namespace and class tag for after name space
namespace backend\controllers;
use common\models\helpers\Frontend\DropdownHelper;
use common\models\Lookup;
use common\models\Partner;
use common\models\PartnerSearch;
use Yii;
use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\web\Response;
Missing file tags and class tags error in phpStorm.
Some parts of your code may be unable to conform to your coding standard. You can ignore file parts in the following way
$xmlPackage = new XMLPackage;
// phpcs:disable
$xmlPackage['error_code'] = get_default_error_code_value();
$xmlPackage->send();
// phpcs:enable
In your case you are trying to ignore the doc block for the page and the class, so you should start the // phpcs:disable before the namespace and then close it using // phpcs:enable right after the opening braces of the class {.
I am adding the sample code to ignore the docs block for the file and class below using my own code as you never added the actual code but the image
<?php
// phpcs:disable
namespace frontend\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\web\Response;
/**
* ApiKeysController implements the CRUD actions for ApiKeys model.
*/
class ApiKeysController extends Controller
{
// phpcs:enable
}
Note: Before PHP_CodeSniffer version 3.2.0, use // #codingStandardsIgnoreStart
instead of // phpcs:disable, and use // #codingStandardsIgnoreEnd instead of
// phpcs:enable. The #codingStandards syntax is deprecated and will be removed in
PHP_CodeSniffer version 4.0.
At the top of file, outside the class, we have:
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
Inside the class, we have:
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
Why it is repeated?
These are traits, which add a defined set of functionality to the class. You can look up this functionality in the Laravel API docs:
https://laravel.com/api/5.6/Illuminate/Foundation/Auth/Access/AuthorizesRequests.html
https://laravel.com/api/5.6/Illuminate/Foundation/Validation/ValidatesRequests.html
https://laravel.com/api/5.6/Illuminate/Foundation/Auth/Access/AuthorizesRequests.html
The use statements up the top are part of PHP's namespaces, which you'll want to get familiar with - this pattern is used all over Laravel's code. Having the use Foo\Bar\Hello\World up the top of the file allows you to do stuff like new World instead of typing out the full new \Foo\Bar\Hello\World throughout the code.
I have an array ($models) which has the names of my modal classes :
<?php
namespace App\Http\Controllers\systemActions;
use Storage;
use App\Accident;
use App\Company;
use App\Driver;
use App\Employee;
use App\Expert;
use App\InputTransaction;
use App\Notification;
use App\Receipt;
use App\Person;
use App\Transaction;
use App\Group;
use App\User;
use App\Permission;
use App\Witness;
use App\Companynote;
use App\RejectedReceipt;
use App\DataEntryNote;
use App\Task;
use App\Setting;
use App\RealEstate;
use App\Oldreportpayment;
use App\Freelancerdataentryaccident;
use App\UserFlow;
use App\Page;
use App\Log;
use App\Damagedetection;
use App\Datarequest;
use App\Eperson;
use App\Edriver;
use App\Eaccident;
use App\Erealestate;
use App\Subcompany;
use App\Subcompanyaccident;
use Faker\Provider\tr_TR\DateTime;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Auth;
use Hash;
use Validator;
ob_start();
session_start();
class readController extends Controller
{
$modals=['Accident','Company','Companynote','Damagedetection','Dataentrynote','Datarequest',
'Driver','Eaccident','Edriver','Eperson','Erealestate','Freelancerdataentryaccident','Garage'
,'Group','Kashef','Notification','Oldreportpayment','Person','Realestate','Receipt','Setting',
'Rejectedreceipt','Subcompany','Subcompanyaccident','Task','Transaction','Userflow','Witness'];
i was trying to use them in the following code statement :
$modals[$x]::create($DB2_Data[$x]);
but iam getting this error :
Class 'Accident' not found
on the other hand, if I put this or anything that is in the model's array, it works fine
Accident::create($DB2_Data[$x]);
so can anyone give me a solution for this problem.
so as our friend suggested up there we need to add them in the array as following : $modals=['App\Accident']
thank you
Error:
Parse error: syntax error, unexpected '$type' (T_VARIABLE), expecting ',' or ')'","exception":"Symfony\Component\Debug\Exception\FatalThrowableError","trace":[{"file":"/home/fiedel/Documents/fol/docs/develop/vendor/composer/ClassLoader.php","line":322,
These are the things included:
use App\Models\Category;
use App\Models\RegistrySession;
use Auth;
use DB;
use App\Models\Registry;
use App\Models\Project;
use App\Models\Enterprise;
use App\Models\User;
use App\Models\Group;
use League\Period\Period;
use Marcelgwerder\ApiHandler\Facades\ApiHandler;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Carbon\Carbon;
use PHPExcel;
use PHPExcel_IOFactory;
use Barryvdh\DomPDF\Facade as PDF;
use App\Models\DailyLog\CaptionDailyUser;
use App\Models\DailyLog\CaptionDailyUserProject;
use App\Models\DailyLog\UserActivityDaily;
Phalcon autoloader is configured in the following way:
$loader = new Phalcon\Loader;
$loader->registerDirs(array(
'../app/4/controllers/',
'../app/models/',
'../app/services',
'../app/forms/',
'../app/vendor/'
))->register();
The directory tree is:
app
├───services
│ ├─── PayPalService.php - important
└───vendor
└───PayPal
├───Api
│ └───Amount.php
│ └───and all other files
├───Auth
├───Common
├───Converter
├───Core
├───Exception
├───Handler
├───Rest
├───Security
├───Transport
└───Validation
At the beginning of PalPalService.php there is:
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
use PayPal\Rest\ApiContext;
Phalcon autoloader apparently can't find these classes so I get error Undefined class constant 'PayPal'. For other classes that don't use namespaces this autoloader works. What is wrong? How to use PayPal SDK without Composer? I think Phalcon's autoloader should deal with it.
I also tried:
$loader->registerNamespaces(
array(
"PayPal" => "../app/vendor/PayPal/"
)
);
It still doesn't find PayPal classes. I don't want to list each PayPal directory because according to docs Phalcon's autoloader should change namespace separator into directory separator.
"../app/vendor/PayPal/" should be "../app/vendor/"
$loader->registerNamespaces(
array(
"PayPal" => "../app/vendor/"
)
);