Runkit : does not work on a linux server - php

I have a problem with PECL::Runkit with this little example
index.php contain <?php
runkit_import('a.php');
runkit_import('b.php');
Doublon::get();
a.php et b.php each contain the same code
class Doublon
{
static function get() { echo "class " . __FILE__; }
}
On my PC (Windows XP, Wampserver 2, php 5.2.9-2, runkit DLL bundled with
Wamp) it work and index.php show
class C:\wamp2\www\utilitaires\essais\runkit\b.php
On my Linux CentOS 5 server, PHP 5.2.10, Runkit compiled by hand
Warning: runkit_import() [function.runkit-import]: class doublon not
found in /shares/public/cedric/test/index.php on line 2
Warning: runkit_import() [function.runkit-import]: Cannot redeclare
class doublon in /shares/public/cedric/test/index.php on line 2
Warning: runkit_import() [function.runkit-import]: class doublon not
found in /shares/public/cedric/test/index.php on line 3
Warning: runkit_import() [function.runkit-import]: Cannot redeclare
class doublon in /shares/public/cedric/test/index.php on line 3
Fatal error: Class 'Doublon' not found in
/shares/public/cedric/test/index.php on line 4
One problem : runkit's make test give me 100% of tests failed, but I still don't know why.
The runkit version from the linux distribution just make crash Apache :
PHP Startup: Timezone database is corrupt
I dropped xdebug, return to php 5.2.9, but the errors are the same
Thanks in advance, Cédric

The Package site says:
WARNING: 0.9 does not compile with PHP 5.2+ so use the CVS version instead.
Are you using the CVS version?

The up-to-date runkit extension can be found on http://github.com/zenovich/runkit
Anyway, as I know, runkit never had a feature to define new class on importing. It only can add or change members of existing classes. If you really want this, you can open the feature-request on http://github.com/zenovich/runkit
To determine why you get different results on your platforms, I need to know the versions of runkit and PHP for both of them. You can get all the information using the command 'php -i'.

Related

How to get threads working in PHP on Windows?

I want to run PHP Thread class code on Windows. I tried some manual installation guides like e.g. this one but they didn't work. PHP cannot load the pthreads DLL even though the file exists at this location:
PHP Warning: PHP Startup: Unable to load dynamic library 'php_pthreads.dll' (tried: C:\xampp\php\ext\php_pthreads.dll (The specified module could not be found), C:\xampp\php\ext\php_php_pthreads.dll.dll (The specified module could not be found)) in Unknown on line 0
I downloaded php_pthreads-3.1.6-7.0-ts-vc14-x64.zip. My PHP version is: PHP 8.1.6 (cli) (built: May 11 2022 08:55:59) (ZTS Visual C++ 2019 x64). Generally I'm still not entirely sure which pthread version to select since there are many choices here. Are any of them even going to work since they seem a bit outdated? My phpinfo says:
Can I maybe just use Windows threads since they are already available on my system?
After the pthreads installation, when I run my Thread class example code
<?php
class AsyncOperation extends Thread
{
public function __construct($arg)
{
$this->arg = $arg;
}
public function run()
{
if ($this->arg) {
printf("Hello %s\n", $this->arg);
}
}
}
$thread = new AsyncOperation("World");
if ($thread->start())
$thread->join();
?>
I still get the warning above and the following error:
PHP Fatal error: Uncaught Error: Class "Thread" not found
What am I doing wrong? Is there maybe a way to do it with less "manual" effort in e.g. 1 composer command or an easier way to get threading working?

PHPUnit Plugin in Netbeans 8.2 gives Fatal error: Class 'PHPUnit_Framework_TestSuite' not found when trying to run a test case

When I try to run PHPUnit in Netbeans I face this error:
Fatal error: Class 'PHPUnit_Framework_TestSuite' not found in C:\Users\julian\AppData\Roaming\NetBeans\8.2\phpunit\NetBeansSuite.php on line 63
Done.
This happens both in Netbeans and CLI.
I started debugging this problem by navigating to this directory: C:\Users\julian\AppData\Roaming\NetBeans\8.2\phpunit\.
That directory contained one file: NetBeansSuite.php. I opened it to look for clues, and saw this line:
class NetBeansSuite extends PHPUnit_Framework_TestSuite {
What I didn't see is any concrete PHPUnit_Framework_TestSuite class.
What's next is that the NetBeansSuite.php file doesn't have any include or require language constructs that may include the PHPUnit_Framework_TestSuite class.
So, in order to fix the fatal error problem I should include the PHPUnit_Framework_TestSuite in NetbeansSuite.php.
This is a problem because I'm not the author of NetbeansSuite.php.
On top of that the author of NetbeansSuite.php wrote this in the comment section:
<b>WARNING: User changes to this file should be avoided.</b>
I read further in the comments:
* Copyright 2010 Oracle and/or its affiliates. All rights reserved.
I guess the NetbeansSuite.php file is outdated.
Searching on the net brought me to this stackoverflow question:
Why, Fatal error: Class 'PHPUnit_Framework_TestCase' not found in ...?
They claim that using a namespaced version of PHPUnit_Framework_TestCase should fix the problem. So I did what they wrote.
I stubbornly changed NetBeansSuite.php.
Old code:
class NetBeansSuite extends PHPUnit_Framework_TestSuite {
New code:
require_once 'PHPUnit/Autoload.php';
use PHPUnit\Framework\TestCase;
class NetBeansSuite extends TestCase {
I tried to run the test case again, and this was the unfortunately result:
Fatal error: Declaration of CalculatorTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in C:\wamp64\www\test\CalculatorTest.php on line 97
In other words, it gave me a new problem.
My system:
Windows 10
WAMP
php 7.2.14
PHPUnit 8.0.6
Netbeans version 8.2 (Netbeans PHPUnit plugin installed through Tools > Plugins. Version: 0.26.2)
My question is: does anybody know how the NetBeansSuite.php file should be like with the system described above?
The setUp method in my test case:
protected function setUp()
{
$this->object = new Calculator;
}
Update: The Skeleton Generator project is abandoned.
See link: https://github.com/sebastianbergmann/phpunit-skeleton-generator
So in order to fix the Declaration of CalculatorTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp() error the corresponding return type declaration should be used in the test case.
// I added : void
protected function setUp(): void
{
$this->object = new Calculator;
}
// : void needs to be added in the tearDown method as well
protected function tearDown(): void
Unfortunately, this gave me new problems:
Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory in C:\wamp64\www\test\CalculatorTest.php on line 4
Fatal error: require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.;C:\php\pear') in C:\wamp64\www\test\CalculatorTest.php on line 4
I solved this by manually installing PEAR and creating a new "PHPUnit" directory in C:\php\PEAR. Then I created a new Autoload.php file. I filled the content of Autoload.php with a PSR-4 example file found at: https://www.php-fig.org/psr/psr-4/.
This solved the Autoload problem, but I faced a new problem during the execution of a test case.
C:\wamp64\www\test>phpunit CalculatorTest.php
PHPUnit 8.0.6 by Sebastian Bergmann and contributors.
Time: 170 ms, Memory: 10.00 MB
No tests executed!
It shows No tests executed! but I have 5 tests.
I'll make a new question for this.
Here it is: PHPUnit 8 installed on Windows through PHAR shows No tests are executed
Initially indeed you should update your namespaces since it has been changed in more recent versions of PHPUnit.
The error however indicates that your CalculatorTest::setUp() method is not compatible with the PHPUnit version. Could you maybe post that method here?
For the same issue, I directly changed the file "NetBeansSuite.php" (C:\Users\USERNAME\AppData\Roaming\NetBeans\8.2\phpunit) as following :
class NetBeansSuite extends \PHPUnit\Framework\TestSuite {
After that, CLI and Netbeans was working.

Hhvm : Arrays are not allowed in class constants

I've a php script that runs ok on my local (MAC High Sierra 10.13.6, php version 7.1.16) using php file.php ...
hhvm --version gives HipHop VM 3.11.0 (rel)
When I run from vagrant (hhvm), it complains Fatal error: Arrays are not allowed in class constants in certainfile.php on line xxx. using hhvm file.php ....
In my file, I've a const defined as:
class Lalala {
const AB_C = array(A::a, B::b,...);
function xyz {...use self::AB_C ...}
}
I tried to change it to
define("AB_C", array(A::a, B::b,...));, but it couldn't even compile with syntax error.
How should I declare the constant arrays here please?
Thank you.
define("AB_C", serialize(array(A::a, B::b,...)));also failed with same syntax error
define("AB_C", jsonencode(array(A::a, B::b,...)));also failed with same syntax error
You can't use arrays as class constants until I believe 3.19, I know it works as of HHVM 3.19.2 but could have been a little bit earlier. If you update HHVM to the latest (or at least a more recent) version, it will work.
https://hhvm.com/blog/2017/04/13/hhvm-3-19.html
Noteworthy changes include:
Const Array support.

Symfony2 date form type: Fatal error: Call to a member function setLenient() on a non-object

thanks to Stof on IRC i know the answer now. I just wanted to share it, in case someone stumbles upon the same problem.
The problem
When you have field type datetime:
/**
* #ORM\Column(type="datetime", name="released_at")
*/
protected $released_at;
and in form type you use date form type:
$builder
->add('released_at', 'date', array(
'widget' => 'single_text',
'format' => 'yyyy-MM-dd',
));
and you're getting this error:
Fatal error: Call to a member function setLenient() on a non-object in (...)\vendor\symfony\src\Symfony\Component\Form\Extension\Core\Type\DateType.php on line 64
The solution is
Try this test
<?php
$formatter = new \IntlDateFormatter();
if($formatter === null)
echo 'null!';
else
echo 'else';
If you get null, it means your php / intl version is buggy and you need to upgrade.
In my case, I was running # Windows 7 64bit machine, Wampserver2 with PHP 5.3.8.
Upgradeing to PHP 5.3.10 or higher did the trick.
Also if you are getting:
(..path..)\StubIntlDateFormatter::setLenient() is not implemented. Please install the 'intl' extension for full localization capabilities.
upgrade to Symfony 2.0.16.
Cheers and once again, TYVM Stof!
I have two configurations, each with a different application:
- Windows 7 64bit machine, Wampserver2 with PHP 5.3.8 with Symfony 2.0.15 installed using composer
- Windows 7 64bit machine, Wampserver2 with PHP 5.3.8 with Symfony 2.1-RC1 installed from zip with vendors
On the first configuration I had the error:
Fatal error: Call to a member function format() on a non-object in C:\MyProject\vendor\symfony\src\Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer.php on line 97
On the second configuration I had the error:
Fatal error: Call to a member function setLenient() on a non-object in C:\MyProjectSf2.1\vendor\symfony\symfony\src\Symfony\Component\Form\Extension\Core\Type\DateType.php on line 81
I upgraded only PHP from 5.3.8 to 5.3.13 in my WAMP2 installation using the files provided at the following place:
http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64-64-bit-for-windows/
PHP 5.3.13 (Thread Safe) + Fixed curl extensions
and it fixed the issues on both applications !
A big thanks to Anindya for his effort offering 64bits compiled version of the PHP DLL, I didn't find an other 64bits version anywhere else !
( and as far as I have seen (I compared the version using Beyond Compare), it was his 5.3.8 64bits thread safe version included in the Wamp2 version I have ;)
Best regards,
Christophe
This happens if you don't have correct parameteres in your php.ini... Check if you have a correct configuration of time zone in your php.ini as "Europe/Brussels" (case sensitive)

Class 'PharData' not found

I get this error on my production server (CentOS 5.4 and php 5.3.5) :
Warning: include_once(PharData.php): failed to open stream: No such
file or directory in /var/www/ZendFramework/library/Zend/Loader.php on
line 146
Warning: include_once(): Failed opening 'PharData.php' for inclusion
(include_path='/var/www/fw:/var/www/vmms:/var/www/ZendFw/library:.:/usr/share/pear:/usr/share/php')
in /var/www/ZendFw/library/Zend/Loader.php on line 146
Fatal error: Class 'PharData' not found in
/var/www/vm/app/Backup.php on line 40
And this is the code which fail :
$phar = new PharData($imageBackupFile);
$phar->buildFromDirectory($imageDir);
Logger::info("Image directory backed up to: $imageBackupFile");
This code is working fine on my own computer.
PharData should be included by default in php 5.3+ ...
Thanks for your help!
UPDATE :
I am using the Zend Auto loader feature to load the good php files using this code :
require_once("Zend/Loader/Autoloader.php");
$autoloader = Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);
Zend autoloader is doing the include_once(PharData.php).
Just because Phar is bundled by default in PHP 5.3 doesn't mean that it's necessarily included in your install. When you build PHP with ./configure, you can pass the --disable-phar to disable the Phar extension.
To confirm this, run the following script:
<?php
phpinfo();
?>
One of the first sections to appear will be the Configure Command section. Review this section to see if the --disable-phar switch is present, and if there is a Phar section to the page in general.
If it's not present, you'll need to contact your host to have it enabled. There's a decent chance, however, that they won't do it for you since it could impact other users depending on how their servers are set up. If this is on your own machine, you'll need to either rebuild PHP without that switch, or install Phar manually from PECL (no idea if this would still work in 5.3, but I don't see why it wouldn't).

Categories