PHP PhantomJS - "use JonnyW\PhantomJs\Client;" Error? - php

I've installed PhantomJS and PHP-PhantomJS per the PHP-PhantomJS docs.
Per the PHP-PhantomJS docs, I have the following lines at the top of a php file:
use JonnyW\PhantomJs\Client;
$client = Client::getInstance();
When executing $client = Client::getInstance();, I get the error:
'JonnyW\PhantomJs\Client' not found
The installer has placed JonnyW\PhantomJs\Client here:
/Applications/myWebApp/vendor/jonnyw/php-phantomjs/src/JonnyW/PhantomJs/Client.php
The script that contains the "use" command is located here:
/Applications/myWebApp/application/controllers/myPHPscript.php
How can I modify the "use" command so as to locate the required "JonnyW\PhantomJs\Client" file?
I have looked at StackOverflow topics that appear similar but don't seem to provide the answer I need.
Thanks in advance to all for any info.

As noted, I followed the PHP-PhantomJS Docs in installing PhantomJS and PHP-PhantomJS. Per those docs, I used Composer to download and install everything. I'd never used Composer before. I learned that the framework I'm using, CodeIgniter, includes support for Composer. All I had to do was activate Composer support in the CodeIgniter config.php file, via the $config['composer_autoload'] setting.

Related

VS Code can not reach Symfony\Component and Symfony\Bundle

I am trying to create a simple symfony project.
I run this on console:
composer create-project symfony/skeleton myProjectName
php -S 127.0.0.1:8000 -t myProjectName/public
Project succesfully run at localhost:8000. However, when I begin to inspect the code, I realized VS Code editor is indicating "Undefined type" error in projectDirectory/src/Kernel.php file. Do you have any ideas why this happens and any suggestions towards solution?
I use PHP v7.4.32 and Symfony 5.4 for development. My helper extentions are PHP Intelephense v1.8.2 and PHP IntelliSense v1.0.11.
projectDirectory/src/Kernel.php
The Error
Since it runs succesfully on browser, I dubted that the classes exist somewhere but the VSCode could not solve the relative paths. Then, I tried a couple of extensions. Installation of PHP v1.22.11089 created by DEVSENSE and PHP Namespace Resolver v1.1.9 created by Mehedi Hassan has solved the problem.

trying to run php artisan tinker returns error "file_exists(): Unable to find the wrapper "hoa" "

I'm trying to open tinker in a Laravel project, but when I run php artisan tinker I get this error:
ErrorException
file_exists(): Unable to find the wrapper "hoa" - did you forget to enable it when you configured PHP?
I can't find everything similar error online, I found only similar errors but with 'wrapper http' .
Does anyone have any suggestions? Thanks
Could this be due to custom code or a library you've imported?
I often find that if I add things to the ServiceProvider or Kernel, they run before many of the artisan commands, and if I've failed to perform the proper "if" checks first, it fails.
I suppose the question I would have in return would be; Is this a fresh Laravel install or have you got custom code and libraries running? I would check there, try removing libraries you've added, HOA from my searching doesn't appear to default to Laravel.
— Happy to revise my answer should more detail be provided
Solved with this command founded on github:
composer require psy/psysh:0.11.2 --dev

Configuration to use php intl package in Laravel 8

I have followed the first answer solution of this question Installing PHP intl extension , so I have introduced in composer the line "ext-intl": "*", and run composer update (everything went smooth), but when I try to use within my controller $collator = locale_get_default(); I receive the following answer:
Error
Call to undefined function App\Http\Controllers\locale_get_default()
I do not know how to link my code to the ext-intl package that I have added to the composer configuration.
Thanks in advance for your help.
--
Thank you for your answer Sergio. I have realized that in the web server the php-intl is operative, so I only need to install it in my development environment (XAMPP over OSx: I will find out and come back). But now a new question has came out, thus:
Even in my web server (where php-intl is running) it seems that there is no effective link between the php and the Laravel levels. I have arrived to this conclusion (that surprises me), because if I make a change in the locale with php, it seems not to take place in Laravel Level. Example:
If I run the following (being the server configuration "en_US"):
setlocale(LC_ALL, "es_ES.utf8");
$collator = locale_get_default();
dd($collator);
the output is "es_ES", but if I run:
setlocale(LC_ALL, "es_ES.utf8");
dd(App::currentLocale());
the output is "en".
By the other side, if I run:
App::setLocale('es');
dd(App::currentLocale());
the output is "es". But if I run:
App::setLocale('es');
$collator = locale_get_default();
dd($collator);
the output is " en_US_POSIX ".
There is something that I am not understanding here! Do I have to change both levels at the same time when a localization change requested by the user takes place, so all functions related in both levels (PHP: uasort(), Laravel: Collection->sort(SORT_LOCALE_STRING)) work synchronized? This seems to be a potential source of inconsistencies! (?)
Thanks for the attention.

PHP class 'Ds\Map' not found

In PHP (version 7.1), I am attempting to use a MAP as opposed to a two dimensional array to handle implicit data type conversion across different data type groups. However, I am receiving the following run-time error:
Class 'Ds\Map' not found
The error occurs on this line of code:
protected $hive_data_type_group_map = new \Ds\Map();
I have checked online, but there is little documentation on Ds\Map, even on PHP's website (click here). Does anyone know how to fix this?
Data Structures is not a built-in PHP extension.
It needs to be installed before use. The installation instructions are available on php.net.
For windows
Download compiled-dll file "php_ds.dll" from https://pecl.php.net/package/ds. Place it in your dir wamp\bin\php\[your_php_version_folder]\ext and include it in your ".ini" file.
It worked for me.
the easiest way on ubuntu:
pecl install ds
Reference: https://www.php.net/manual/en/ds-deque.allocate.php

namespace class not found

I want to use this php library "Math-php-master" in my php script.
it is using namespaces.
My script is outside the library folder and the folder for the library is "MathPHP"
There is a php file "Finance.php" which I want to access.
path is "MathPHP/Finance.php". finance.php is using namespace MathPHP
and there is function irr() inside Finance.php which I need.
My code for accessing in my script is below:
include 'MathPHP/Finance.php';
use MathPHP\Finance;
$s = new MathPHP\Finance;
$val = $s->irr(array);
but when I run the script it is giving error "Uncaught Error: Class 'MathPHP\Finance' not found"
I tried everything, I tried the code given on github by the author but it is not working at all
link to the library on github: https://github.com/markrogoyski/math-php
Please help me.
thanks
You have not gone through the effort of readying the readme on how to use the library. In PHP most projects use composer and its autoloading to load classes.
Install composer if you do not have it https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx
In short as the documentation suggests do
php composer.phar require markrogoyski/math-php:0.*
And in your code
require_once(__DIR__ . '/vendor/autoload.php');
use MathPHP\Finance;
// the rest of the code here

Categories