I am using this php wrapper for multichain's json rpc api: https://github.com/Kunstmaan/libphp-multichain in a php file.
I'm not sure how I should adjust my code and I'm reluctant to adjust the libraries so I wanted to check this understanding:
<?php
require_once 'libphp-multichain/src/be/kunstmaan/multichain/MultichainClient.php';
require_once 'libphp-multichain/src/be/kunstmaan/multichain/MultichainHelper.php';
$client = new MultichainClient("http://107.170.46.124:port",{usr},{pwd});
print_r($client);
The error I see in apache error log is:
PHP Fatal error: Class 'MultichainClient' not found in /var/www/html/new.php on line 5
Previously I had the wrong question on here which was referring to a php error treating MultichainClient as a function
this is not a function, you're trying to declare an instance of a new class object. so add the new keyword
$client = new MultichainClient("multichainrpc","password","host","port",3);
Related
I am working with large heavily nested JSON file, and want to use streaming parser by implementing a Listener interface found on jsonstreamingparser. When I ran by php code, I receiced this error:
Fatal error: Uncaught Error: Class 'InMemoryListener' not found in C:\xampp\htdocs. I think the error is on line that contains "$listener = new InMemoryListener();". I am new to using stream parser for JSON in PHP. I know what listener interface does is similar to what XMLPARSER does, and some kind of PHP listener interface has been created by some gurus, but I do not know how to implement it in my code. I put the supposed listener interface file named "InMemoryListener" in the same folder as my php code, but I still got error. Can anyone explain how I can implement the Listener interface in my code?
Below is my code:
$stream = fopen('myJSONfile.json', 'r');
$listener = new InMemoryListener();
try {
$parser = new \JsonStreamingParser\Parser($stream, $listener);
$parser->parse();
fclose($stream);
} catch (Exception $e) {
fclose($stream);
throw $e;
}
?>
Thanks.
When you install something with composer you need to ensure that composer's autoloader is included in your script execution. Add this to the top of your file:
require_once 'vendor/autoload.php';
Next, by the looks of the module you'll need to add a namespace to InMemoryListener as well:
$listener = new \JsonStreamingParser\Listener\InMemoryListener();
I'm trying to learn the basics of Slim 3 and I have difficulties trying to figure out the proper way to organise my custom code, esp. custom classes. For instance, I want to create a custom error handler:
<?php
namespace App\Handlers;
// [...]
final class Error extends \Slim\Handlers\Error
{
// [...]
}
... but the documentation I've checked hasn't revealed under which path to save the class definition or how to configure the framework so it can be found in my index.php entry point:
<?php
require __DIR__ . '/../vendor/autoload.php';
// [...]
$app = new \Slim\App(['settings' => ['displayErrorDetails' => true]]);
$container = $app->getContainer();
$container['errorHandler'] = function ($c) {
return new App\Handlers\Error($c['Logger']);
};
Fatal error: Class 'App\Handlers\Error' not found
I'd appreciate any hint.
You're problem is not related to the framework at all.
Slim doesn't tell you where to keep your custom code because it's a matter of your free choice.
Your error:
Fatal error: Class 'App\Handlers\Error' not found
is not generated by Slim, but PHP itself. You need to add an autoloader for your code to let PHP know where to find appropriate classes.
I can see that you utilize Composer, therefore it's the best option to configure composer.json to create autoloader for your code.
I am using this php wrapper for multichain's json rpc api: https://github.com/Kunstmaan/libphp-multichain in a php file.
The error I see in apache error log is:
PHP Fatal error: Class 'MultichainClient' not found in /var/www/html/new.php on line 5
I'm not sure how I should adjust my code and the wrapper looks:
My code:
<?php
require_once 'libphp-multichain/src/be/kunstmaan/multichain/MultichainClient.php';
require_once 'libphp-multichain/src/be/kunstmaan/multichain/MultichainHelper.php';
$client = new MultichainClient("http://107.170.46.124:port",{usr},{pwd});
print_r($client);
</code>
MultichainClient.php Code
The "MultichainClient" class is namespaced. You need to use the namespace as well as the class name when "calling" the class.
$client = new be\kunstmaan\multichain\MultichainClient();
I've generated a set of php classes using easyWsdl2PHP and they are working ok, but when I place the generated class inside a namespace like such...
namespace myCompany\ourService
then initially when calling this code...
$params = array("classmap"=>self::$classmap,"trace" => true,"exceptions" => true);
$this->soapClient = new SoapClient($url,$params);
I get this error
Class 'myCompany\ourService\SoapClient' not found
which I fix by calling new \SoapClient($url... (notice the backslash at the start, escapes the namespace), but now basically it is complaining it cant find the 'response' object, that is my Request is placed in a 'SALE' object and passed to the soap call, the error is like so
Uncaught SoapFault exception: [Client] Class 'SALEResponse' not found
How can I use php namespaces correctly within my code, how to get Soap in php to use the name spaces correctly? I have two very similar services I need to connect to, both with 'sale' methods, and many other commonly named elements that are not compatible, so placing them inside a php namespace appears to be a good solution, as the code is generated, I could rename each Sale to Service1_Sale and Service2_Sale, but that is far from ideal. Any help?
I've found a solution :
private static $classmap = array('SALE'=>'ourCompany\ourService\SALE'
,'SALEREQUEST_V1'=>'ourCompany\ourService\SALEREQUEST_V1'
,'AUTHORIZATION_V1'=>'ourCompany\ourService\AUTHORIZATION_V1'
,'RECEIPTREQUEST_V1'=>'ourCompany\ourService\RECEIPTREQUEST_V1'
,'SALEResponse'=>'ourCompany\ourService\SALEResponse'
);
where i've added the ourCompany\ourService\ to include the namespace i'm using.
I am trying to write a PHP client for a Thrift server written in C. I am following the tutorial given at http://chanian.com/2010/05/13/thrift-tutorial-a-php-client/.
I am very new to PHP and, I suspect, am missing some of the language fundamentals.
The code in question is:
<?php
// Setup the path to the thrift library folder
$GLOBALS['THRIFT_ROOT'] = 'Thrift';
// Load up all the thrift stuff
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
// Load the package that we autogenerated for this tutorial
require_once $GLOBALS['THRIFT_ROOT'].'/packages/encabulationgame/EncabulationGame.php';
// Several things might go wrong
try {
// Create a thrift connection (Boiler plate)
$socket = new TSocket('localhost', '65123'); <--error is here
I am getting an error "Class 'TSocket' not found in /var/www/foo/scores.php on line 22"
TSocket is defined in Thrift/transport/TSocket.php. The Thrift/transport/TSocket.php file (with comments removed) reads:
<?php
namespace Thrift\Transport;
use Thrift\Transport\TTransport;
use Thrift\Exception\TException;
use Thrift\Exception\TTransportException;
use Thrift\Factory\TStringFuncFactory;
/**
* Sockets implementation of the TTransport interface.
*
* #package thrift.transport
*/
class TSocket extends TTransport {
If I change my code to:
$socket = new Thrift\Transport\TSocket('localhost', '65123');
Then my code (well, this line, at least) no longer throws an error. I'm curious: what did the author of this tutorial do to get this code to work on his system that I'm not doing on my system?
Secondly, I attempted to solve the problem by adding the line:
use Thrift\Transport;
to my file before I create $socket, but that didn't solve the problem as I'd expected it to.
How do I convince PHP to resolve this type that's defined in another file? (There are several types in several files that I have to resolve.)
PHP does not import an entire namespace, instead you must "use" each namespaced class you wish to import. Instead of use Thrift\Transport; write
use Thrift\Transport\TSocket;
This is described in more detail in the manual under Using Namespaces: Aliasing/Importing. Is it possible that the article was written before Thrift was namespaced?