Loading my built PHP modules failed with no error - php

I built my hello_world php module by following tihs: https://zando.io/post/hello-world-php-7-extension/
And I successfully built a hello.so under modules/
But when I tried to load this hello.so, it failed.
(adding extension=hello.so to php.ini and put the .so file to extension_dir)
var_dump(extension_loaded('hello'));
var_dump(hello_world());
Output:
bool(false)
Fatal error: Uncaught Error: Call to undefined function hello_world() in /var/www/app/test.php(2) : eval()'d code:1 Stack trace: #0 /var/www/app/test.php(2): eval() #1 {main} thrown in /var/www/app/test.php(2) : eval()'d code on line 1
But when I tried to load my friend's hello_world so file, it works!!
(same source code, same building process...)
I really don't know why...

I have solved this problem.
Because I use the wrong version of phpize and php-config.
The phpinfo() shows that PHPAPI is 20170718
But my original phpize shows 20180731
So I reinstall the php7.2-dev.
Then run phpize7.2 and then ./configure --with-php-config=/usr/bin/php-config7.2 to configure the settings.
And it works!

Related

Fatal error: Uncaught Error: Call to undefined function get_json_data()

Here's the error upon opening php file using Docker Desktop:
0.1.2
Fatal error: Uncaught Error: Call to undefined function get_json_data() in C:\laragon\www\myproject\public\index.php:37 Stack trace: #0 C:\laragon\www\myproject\public\index.php(40): get_channels() #1 {main} thrown in C:\laragon\www\myproject\public\index.php on line 37
Local link is: localhost
I have the ff. extensions installed on VSCode:
PHP Debug
PHP Intelephense
PHP Extension Pack
PHP IntelliSense
use json_decode instead of get_json_data
It seems that the edit in settings.JSON inside VS Code had this wrong path:
"php.validate.executablePath": "C:/xampp/php/php.exe"
I had to delete the project and clone it again and now it works fine. Path shows:
"php.validate.executablePath": "C:/laragon/bin/php/php-7.4.19-Win32-vc15-x64/php.exe",
Thank you!

Phalcon - Class "Phalcon\Config" not found

I've installed Phalcon and trying to create new project: phalcon project store. But instead of this I get these errors:
PHP Fatal error: Uncaught Error: Class "Phalcon\Config" not found in C:\Composer\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php:48
Stack trace:
#0 C:\Composer\vendor\phalcon\devtools\src\Commands\Builtin\Project.php(74): Phalcon\DevTools\Builder\Component\AbstractComponent->__construct(Array)
#1 C:\Composer\vendor\phalcon\devtools\src\Script.php(109): Phalcon\DevTools\Commands\Builtin\Project->run(Array)
#2 C:\Composer\vendor\phalcon\devtools\src\Script.php(148): Phalcon\DevTools\Script->dispatch(Object(Phalcon\DevTools\Commands\Builtin\Project))
#3 C:\Composer\vendor\phalcon\devtools\phalcon(65): Phalcon\DevTools\Script->run()
#4 {main}
thrown in C:\Composer\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php on line 48
Fatal error: Uncaught Error: Class "Phalcon\Config" not found in C:\Composer\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php:48
Stack trace:
#0 C:\Composer\vendor\phalcon\devtools\src\Commands\Builtin\Project.php(74): Phalcon\DevTools\Builder\Component\AbstractComponent->__construct(Array)
#1 C:\Composer\vendor\phalcon\devtools\src\Script.php(109): Phalcon\DevTools\Commands\Builtin\Project->run(Array)
#2 C:\Composer\vendor\phalcon\devtools\src\Script.php(148): Phalcon\DevTools\Script->dispatch(Object(Phalcon\DevTools\Commands\Builtin\Project))
#3 C:\Composer\vendor\phalcon\devtools\phalcon(65): Phalcon\DevTools\Script->run()
#4 {main}
thrown in C:\Composer\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php on line 48
My PHP version is 8.0.8 Thread Safe x64, I've installed PSR extension and Phalcon 5.0.0 from here: https://github.com/phalcon/cphalcon/releases/tag/v5.0.0beta3, file phalcon-php8.0-ts-windows2019-vs16-x64.zip, that means I have compatible version of framework. phalcon.bat was added to environment variables. What's the problem?
Usually this error occurs when the extension is not loaded by php, see with phpinfo(), also run the componser install insider phalcon-devtools, but probably it is the php not loading the phalcon extension or PHP is not in the windows PATH , also check if the php-fpm log does not contain any extension loading errors, test in cmd the command php -v
also create a index.php and try it
<?php
use Phalcon\Mvc\Micro;
$app = new Micro();
$app->get('/', function () { echo "<h1>test</h1>";});
$app->handle();
Try do the following Go to Edit The system environment variables -> system variables -> path -> edit add phalcon.bat folder path testing here i used C:\Users\renato\Downloads\phalcon-devtools-4.2.0\phalcon-devtools-4.2.0 ( just path folder where the .sh/.bat it is, do not include the file and extension) and worked fine with php 8.0.16 windows 10 phalcon 5
and then go to the power shell and input phalcon
https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/
Do not forget to run composer install inside phalcon devtools folder.
also on powershell input php -m to see the loaded modules and if it has an error

PEAR on PHP 7.2 on Windows 10

On a clean Windows installation I installed PHP 7.2 with Nginx which works fine, both via Nginx as on the commandline. Now, I also want to install PEAR but that will output som PHP errors which don't fully know why the happen.
Bellow the full output of the command php .\go-pear.phar which I got from the official documentation page http://pear.php.net/manual/en/installation.getting.php.
Name of configuration file [C:\WINDOWS\pear.ini] : $prefix
Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the
directory. Type 'all' to change all of them or simply press Enter to
accept these locations.
1. Installation base ($prefix) : C:\tools\php
2. Temporary directory for processing : C:\tools\php\tmp
3. Temporary directory for downloads : C:\tools\php\tmp
4. Binaries directory : C:\tools\php
5. PHP code directory ($php_dir) : C:\tools\php\pear
6. Documentation directory : C:\tools\php\docs
7. Data directory : C:\tools\php\data
8. User-modifiable configuration files directory : C:\tools\php\cfg
9. Public Web Files directory : C:\tools\php\www
10. System manual pages directory : C:\tools\php\man
11. Tests directory : C:\tools\php\tests
12. Name of configuration file : C:\tools\php
13. Path to CLI php.exe : C:\tools\php
1-13, 'all' or Enter to continue:
Beginning install...
PHP Fatal error: Uncaught Error: Call to undefined method PEAR_Error::set() in phar://C:/tools/php/go-pear.phar/PEAR/Start.php:322
Stack trace:
#0 phar://C:/tools/php/go-pear.phar/PEAR/Start/CLI.php(72): PEAR_Start->doInstall()
#1 phar://C:/tools/php/go-pear.phar/index.php(5): PEAR_Start_CLI->run()
#2 C:\tools\php\go-pear.phar(1271): require_once('phar://C:/tools...')
#3 {main}
thrown in phar://C:/tools/php/go-pear.phar/PEAR/Start.php on line 322
Fatal error: Uncaught Error: Call to undefined method PEAR_Error::set() in phar://C:/tools/php/go-pear.phar/PEAR/Start.php:322
Stack trace:
#0 phar://C:/tools/php/go-pear.phar/PEAR/Start/CLI.php(72): PEAR_Start->doInstall()
#1 phar://C:/tools/php/go-pear.phar/index.php(5): PEAR_Start_CLI->run()
#2 C:\tools\php\go-pear.phar(1271): require_once('phar://C:/tools...')
#3 {main}
thrown in phar://C:/tools/php/go-pear.phar/PEAR/Start.php on line 322
The answer is actually on a page of the documentation:
https://pear.php.net/manual/en/installation.php
Windows 7 will not allow the installation script to write to c:\windows\pear.ini. It gives the "Fatal error: Call to undefined method PEAR_Error::set()" error. Change the location of the configuration files (#11) to someplace writable, complete the installation, then copy the contents into c:\windows\pear.ini.
A simple solution to this is: Run cmd as administrator.

Fatal error: Uncaught Error: Call to undefined function Symfony\Polyfill\Mbstring\iconv() in phar:

I use Ubuntu 16.04 LTS
PHP 7.0.13
NetBean
I try to run some actions linked with composer in the NetBeans environment
I had these logs
"/usr/local/ampps/php-7.0/bin/php" "/home/arfa/www/composer.phar" "--ansi" "--no-interaction" "self-update"
Fatal error: Uncaught Error: Call to undefined function Symfony\Polyfill\Mbstring\iconv() in phar:///home/arfa/www/composer.phar/vendor/symfony/polyfill-mbstring/Mbstring.php:520
Stack trace:
#0 phar:///home/arfa/www/composer.phar/vendor/symfony/polyfill-mbstring/bootstrap.php(46): Symfony\Polyfill\Mbstring\Mbstring::mb_strwidth(' [Composer\\Exc...', 'ASCII')
#1 phar:///home/arfa/www/composer.phar/vendor/symfony/console/Application.php(1106): mb_strwidth(' [Composer\\Exc...', 'ASCII')
#2 phar:///home/arfa/www/composer.phar/vendor/symfony/console/Application.php(650): Symfony\Component\Console\Application->stringWidth(' [Composer\\Exc...')
#3 phar:///home/arfa/www/composer.phar/vendor/symfony/console/Application.php(131): Symfony\Component\Console\Application->renderException(Object(Composer\Exception\NoSslException), Object(Symfony\Component\Console\Output\StreamOutput))
#4 phar:///home/arfa/www/composer.phar/src/Composer/Console/Application.php(100): Symfony\Component\Console\Application->run(Object(Symfony\Component\ in phar:///home/arfa/www/composer.phar/vendor/symfony/polyfill-mbstring/Mbstring.php on line 520
Done.
The issue is linked to my project, symfony, settings.
Do you have the iconv extension enabled?
Please post the reply of this command:
php -i | grep -i "iconv support"
Or, search your php.ini file for "extension=iconv.so", if it's commented out, uncomment it and make sure you restart Apache.
If that fails, try installing the composer package:
composer require symfony/polyfill-iconv

Using composer with php in non standard location

I'm trying to use composer on my NAS (a good old D-Link DNS-323 running the incredibly good fonz fun plug 0.7).
I have my php installed in /ffp/bin/php.
When I install composer using the following command
php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/ffp/sbin --filename=composer
But when I do a simple less /ffp/sbin/composer, I have the following shebang set :
#!/usr/bin/env php
<?php
/*
* This file is part of Composer.
*
Unfortunatly, my NAS do not have the /usr/bin/env folder existing on my machine ...
So, how can I have composer referring to the correct php executable ?
Besides, I tried changing the declaration to use #!/ffp/bin/php, but when doing so, any composer run echoes the following result :
PHP Warning: PHP Startup: Unable to load dynamic library '/ffp/lib/php/extensions/no-debug-non-zts-20100525/gd.so' - File not found in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library '/ffp/lib/php/extensions/no-debug-non-zts-20100525/gd.so' - File not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/ffp/lib/php/extensions/no-debug-non-zts-20100525/sqlite.so' - File not found in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library '/ffp/lib/php/extensions/no-debug-non-zts-20100525/sqlite.so' - File not found in Unknown on line 0
PHP Fatal error: Uncaught exception 'PharException' with message 'phar "/mnt/HD_a2/ffp/sbin/composer" has a broken signature' in /mnt/HD_a2/ffp/sbin/composer:23
Stack trace:
#0 /mnt/HD_a2/ffp/sbin/composer(23): Phar::mapPhar('composer.phar')
#1 {main}
thrown in /mnt/HD_a2/ffp/sbin/composer on line 23
Fatal error: Uncaught exception 'PharException' with message 'phar "/mnt/HD_a2/ffp/sbin/composer" has a broken signature' in /mnt/HD_a2/ffp/sbin/composer:23
Stack trace:
#0 /mnt/HD_a2/ffp/sbin/composer(23): Phar::mapPhar('composer.phar')
#1 {main}
thrown in /mnt/HD_a2/ffp/sbin/composer on line 23
Of particular importance is the line
PHP Fatal error: Uncaught exception 'PharException' with message 'phar "/mnt/HD_a2/ffp/sbin/composer" has a broken signature' in /mnt/HD_a2/ffp/sbin/composer:23
How can i fix it ? In other words, how can I have a working php + composer installation on my NAS ?
So, how can I have composer referring to the correct php executable ?
A very simple solution is to create a shell script:
#!/bin/sh
/ffp/bin/php -n /ffp/sbin/composer "$#"
Make it executable, name it composer, put it in your path before /ffp/sbin (or rename /ffp/sbin/composer to composer.phar and update the above script too).
The -n flag tells PHP to not use php.ini. This is useful when there are many extensions loaded from php.ini; not loading them makes composer run faster. Especially xdebug is recommended to not be loaded by composer, for speed improvement.

Categories