Recently I've updated my composer to 1.0.3. After that I'm getting following error. "PHP Fatal error: Cannot redeclare class Error"
Here is my sample code.
<?php
require "./vendor/autoload.php";
require "MyErrorLog.php"; // Class file having class name as "Error"
Previously, I was using some code without having any problem. But, after updating composer & it's dependance I'm getting this error.
Shall I need to use a namespace to resolve this or something else I need to do?
If I use following the piece of code.
require "./vendor/autoload.php";
$Error = new Error();
echo '<pre>';
print_r($Error);
echo '</pre>';
I'm getting this out put.
Error Object
(
[message:protected] =>
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /var/www/testing/composer-test1/composer-test.php
[line:protected] => 7
[trace:Exception:private] => Array
(
)
[previous:Exception:private] =>
)
Anyone, help me to understand what's exactly it is & what it's uses?
Adding my composer.json file content
{
"require": {
"defuse/php-encryption": "^2.0"
}
}
Related
Very new to php unit and can't exactly work out whats wrong. My class is as follows:
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/assets/php/global_php_includes.php';
use PHPUnit\Framework\TestCase;
final class PesticideTests extends TestCase {
public function addPesticideTest() {
$data = array(
"code" => randomString(16),
"created_by" => $_SESSION['userCode'],
"company_code" => "TEST_COMPANY",
"crop_code" => "TEST_CROP",
"content" => "TEST_CONTENT",
"comments" => "TEST_COMMENTS",
"function" => "TEST_FUNCTION",
"pcs_no" => 0123,
"phi" => "TEST_PHI",
"product_name" => "TEST_PRODUCT",
"substance" => "TEST_SUBSTANCE",
"date_of_reg_review" => "01-01-0001",
"use_by_date" => "01-01-0001",
"off_label_approval" => "TEST_OFF_LABEL_APPROVED",
"latest_time_of_application" => "TEST_LATEST_TIME_OF_APPLICATION",
"max_individual_dose" => "TEST_MAX_INDIVIDUAL_DOSE",
"max_total_dose" => "TEST_MAX_TOTAL_DOSE",
"max_no_applications" => "TEST_MAX_NO_APPLICATIONS",
"method_of_application" => "TEST_METHOD_OF_APPLICATION",
"status" => 'inactive'
);
$result = addPesticide($connection, $data);
$this->assertEquals(1, $result);
}
}
the command I run to test it is ./vendor/bin/phpunit tests/PesticideTests.php
and the error I get is
PHP Warning: include(/assets/php/global_php_includes.php): failed to open stream: No such file or directory in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
Warning: include(/assets/php/global_php_includes.php): failed to open stream: No such file or directory in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
PHP Warning: include(): Failed opening '/assets/php/global_php_includes.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
Warning: include(): Failed opening '/assets/php/global_php_includes.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
PHPUnit 9.5.2 by Sebastian Bergmann and contributors.
W 1 / 1 (100%)
Time: 00:00.014, Memory: 4.00 MB
There was 1 warning:
1) Warning
No tests found in class "PesticideTests".
WARNINGS!
Anyone have any idea what I'm doing wrong? If I also run it as just ./vendor/bin/phpunit tests then I get the error "No tests found". Pretty confused
EDIT:
I have fixed the test not being found by naming it by the wrong convention, still getting an error for the include file
When running your code withing phpunit there is no $_SERVER['DOCUMENT_ROOT'] set. This only gets set when running in the context of a webserver. Just replace this with the directory where the assets directory is.
Im not good usig php, i just installed composer and just created this composer.json in my new project directory:
{
"require": {
"chatapi/whatsapp": "dev-master"
}
}
then I created a file named "whatsapp-sender.php" with the following:
<?php
require "vendor/autoload.php";
$client = Client::getInstance([
'url' => '<ULR>',
'token' => '<TOKEN>'
]);
$client->sendMessage([
'phone' => '<PHONE_NUMBER>',
'body' => 'Hi there!'
]);
?>
but when i try to run it to send a message this error appeared:
F:\BotGenes\PHP\Chat-api>php whatsapp-sender.php PHP Fatal error:
Uncaught Error: Class 'Client' not found in
F:\BotGenes\PHP\Chat-api\whatsapp-sender.php:5 Stack trace:
0 {main} thrown in F:\BotGenes\PHP\Chat-api\whatsapp-sender.php on line 5
Fatal error: Uncaught Error: Class 'Client' not found in
F:\BotGenes\PHP\Chat-api\whatsapp-sender.php:5 Stack trace:
0 {main} thrown in F:\BotGenes\PHP\Chat-api\whatsapp-sender.php on line 5
Can somebody help me please?
So I just started to learn Redis and tried to install it for PHP using this link :- https://github.com/nrk/predis
I installed it via composer and then ran :-
require 'autoload.php';
$client = new Predis\Client(array('host' => "127.0.0.1", "port" => 6379, array("prefix" => "php:")));
$client->set("string:k", "something");
However, this generates error :-
Fatal error: Uncaught Error: Class 'Predis\Configuration\Options' not found in /Library/WebServer/Documents/redis/2/src/Client.php on line 74
Error: Class 'Predis\Configuration\Options' not found in /Library/WebServer/Documents/redis/2/src/Client.php on line 74
What is wrong here?
You have to register Predis Autoloader like this
require __DIR__ . '/vendor/autoload.php'; //autoload vendor see https://getcomposer.org/doc/01-basic-usage.md#autoloading
$client = new Predis\Client(array('host' => "127.0.0.1", "port" => 6379, array("prefix" => "php:")));
$client->set("string:k", "something");
I am trying to dynamically create Subdomains from my website CMS.
I have created the following script:
require_once "/usr/local/cpanel/php/cpanel.php";
$cpanel = new CPANEL();
$get_userdata = $cpanel->uapi(
'DomainInfo', 'domains_data',
array(
'format' => 'hash',
)
);
$addsubdomain = $cpanel->api2(
'SubDomain', 'addsubdomain',
array(
'domain' => ''. $subdomain .'',
'rootdomain' => 'REMOVED',
'dir' => '/public_html/',
'disallowdot' => '1',
)
);
I am getting the following error:
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'There was a problem fetching the env variablecontaining the path to the socket' in /usr/local/cpanel/php/cpanel.php:146
Why is this and what am I doing wrong?
You get this error when you're trying to use LiveAPI in PHP Script outside the cPanel's document root.
According to cPanel, LiveAPI can be used only from withing cPanel's document root: /usr/local/cpanel/base/frontend/, /usr/local/cpanel/base/3rdparty/.
Using the Facebook REST API PHP client library, it seems wise to wrap calls in try{} thus:
require('facebook.php');
$fb = new Facebook($fbApiKey, $fbSecret);
try {
$result = $fb->api_client->some_api_method(...);
} catch (FacebookRestClientException $e) {
// now what?
}
But I'm not sure what to do with the exception, e.g. to find out what went wrong or to write a sensible message to the error log. Is there documentation for these exceptions somewhere?
After examining the code and some example exceptions, I think $e is an object looking something like this:
(
[message:protected] => An error message string
[string:Exception:private] => Don't know
[code:protected] => A numerical error code
[file:protected] => File here the exception was thrown
[line:protected] => Line where the exception was thrown
[trace:Exception:private] => A PHP debug_backtrace() result
[previous:Exception:private] => Don't know
)