Attempted to call function "openssl_pkey_get_private" from namespace "WAYF" - php

I'm getting this error message
Attempted to call function "openssl_pkey_get_private" from namespace "WAYF"
I'm upgrading the symfony version from symfony2 to symfony3, and "WAYF" is my bundle and
In that I have one class name as "CustomLogin.php"
in that class I have declared one function "function prepareparamsforjs(){}" and
in that function I'm calling "openssl_pkey_get_private()" function with arguments "$privatekey" and "$privatekeypass" to get a private Key
but I'm getting above error message.
Can anybody tell me how to solve this issue.
Thanks in Advance!...

IMHO you don't have the OpenSSL extension (http://php.net/manual/en/book.openssl.php) loaded in PHP, so the parser is trying to find it inside the current namespace, which is the WAYF.
A quick way to verify if the OpenSSL extension is loaded is to run:
var_dump(extension_loaded('openssl'));

Related

fig/link-util not compatible with psr/link

I installed a fresh Symfony v5.3, ApiPlatform v2.6.6. When I enter to /api url I'm getting that error:
Fatal error: Declaration of Fig\Link\Link::withHref(Stringable|string $href):
Symfony\Component\ErrorHandler\DebugClassLoader must be compatible with
Psr\Link\EvolvableLinkInterface::withHref($href) in
/api-platform-course/vendor/fig/link-util/src/Link.php on line 22
I opened that file with editor: vendor/fig/link-util/src/EvolvableLinkTrait.php and it is implementing that interface: Psr\Link\EvolvableLinkInterface. It seems this trait isn't correctly implementing methods. For example interface's method is this:
public function withHref(string|\Stringable $href);
EvolvableLinkTrait::withHref method implementation is this:
public function withHref(\Stringable|string $href): static
As you can see original method hasn't static keyword but implementation has. I removed the static return type hint from implementation but I'm getting same error still. Then I removed all type hints from implementation and error is gone. My current implementation is that:
public function withHref($href)
Everything fine for this method. Other methods has same problem too and I fixed with same way (withRel(), withoutRel(), withAttribute(), withoutAttribute() methods).
I'm using PHP 8.0 and Nginx server. What do you offer for this problem? Must I change package versions or lower Symfony version or anything else? Thanks.
It looks like fig/link-util may need to update the package constraints.
fig/link-util:1.2.0 is type hinted which means its should have
"psr/link": "^2.0.0" as a required package not "psr/link": "^1.1.0 | ^2.0.0"
it also says it provides a 1.0 psr/link-implementation but that should say 2.0.

How can I prevent built in PHP functions from becoming namespaced?

I'm new to PHP namespaces, what I have is:
namespace Foo\Bar;
class JsonAssetRest{
static function ini(){
$headers = getallheaders();
}
}
JsonAssetRest::ini();
And this is creating the error
Uncaught Error: Call to undefined function Foo\Bar\getallheaders() in /var/www/html/class JsonAssetRest.php
How do I use getallheaders() (the built in function) without getting this error?
Edit: The issue was related to removing a library while I was converting my code to a namespaced class. Said library defined getallheaders for nginx. I was confused by the error message adding namespacing and thought that was the issue.
Gonna leave this up in case someone else gets confused by the error while debugging. And because the comments have improved my understanding of namespacing in PHP.
Edit2: In case someone stumbles upon this error and wants to know how to solve the actual problem (getallheaders not being defined under nginx), it's been answered here: Get the http headers from current request in PHP
Global functions are available from any namespace. You do NOT need to add a \ prefix like the other answers suggest.
This error means that there is no function defined in the global or current namespace named getallheaders(). This function is an alias to apache_response_headers() which also likely doesn't exist. I'm assuming that PHP is not running as an apache module which is required for these functions.
By adding a backslash in front of the function like so: $headers = \getallheaders();
If you do not add this backslash in front of the function, it will assume that the function is in the same namespace as the class it is called from. Adding the backslash makes it so that it will look for that function in the global namespace, which is where the function lives.

PHP5.5: Fatal error: Cannot redeclare class

since I upgraded from PHP 5.2 to 5.5 I get an error I don't understand by now.
Fatal error: Cannot redeclare class sessionHandler in ... on line ...
Well before updating the PHP version this error didn't raise and redeclaring a class should be an error independent from PHP version as I guess. Further I always use require_once() which should help to avoid a mistake on that.
So just to make sure it doesn't be redeclared, I added a backtrace code block before that class declaration. So hopefully, I thought it would output twice, but I get only one backtrace output at all. Therefore it gets declared only once from my point of few.
Do I miss something? Any idea how to find the "real" issue?
Class "SessionHandler" already exists in the namespace as it's a class in PHP - http://php.net/manual/en/class.sessionhandler.php
Looks like the class was included in PHP 5.4 so it explains everything.
Try to think of some other name for the class or define a namespace.
If you create a namespace, something like..
namespace App;
class sessionHandler {
....
you won't get the error anymore but you will need to use App\sessionHandler whenever you're referring to your own class.

PHP autoloader not working

I seem to have some misconceptions on how autoloading works in PHP still, one I simply cannot explain.
I have a class called glue which has a spl_autoload_register within it's main function, here called run like so:
class glue{
public static function run(){
spl_autoload_register(array('glue','autoload'));
}
}
The autoload function works by loading via the PSR-0 standard and works from absolute paths. This is all tested as working etc. Note that glue is not namespaced.
The autoload function covers a namespace called glue. Within this namespace I have a error handler called \glue\ErrorHandler.
When I trigger an error the glue class will autoload \glue\ErrorHandler by PSR-0 notation from the root directory as defined by a stored ROOT constant. This has been tested as working as well in classes such as \glue\User and \glue\Session.
So now for the problem. I cause a Call-time pass-by-reference has been deprecated error within \glue\Validation and it doesn't seem to run my autoload function.
I can see how it is going into my autoload function for everything but when I call this error in that class it just seems to skip my autoloader and bail out saying it can't find my error handler class.
Normally I would say it is something with my programming but I have tried everything. I cannot explain how, for this one error. What compounds my confusion further is that if I cause a:
syntax error, unexpected T_ISSET in /media/server_ws/xxxxxxx/glue/Validation.php on line 47
Error it works. It seems to be for that one error it just will not autoload my error handler.
I thought this might be because my spl_autoload_register is not being binded to that namespace (since the error handler that works is actually called from within glue) and some how, maybe, it is randomly working. So from \glue\Validation I called a class I have never looked at: \glue\util\Crypt but that works and goes into the autoloader correctly.
When I call this error: Call-time pass-by-reference has been deprecated from within glue class it works perfectly.
Can anyone shed some light on this?
Edit
As requested here is a brievated version of Validation.php:
namespace glue;
use glue,
\glue\Exception,
\glue\Collection;
class Validation extends \glue\Component{
private function validateRule($rule){
// This is the line, notice the pass by reference down there?
$valid = $validator($field,$field_value,$params,&$this->model) && $valid;
}
}
The Call-time pass-by-reference has been deprecated error is thrown during script compilation, and auto-loading is disabled during compilation. It's disabled because the compiler cannot start compiling multiple scripts at the same time (i.e. it is not re-entrant), and auto-loading may load some script, which may require compiling it.
Source: https://github.com/php/php-src/blob/76ad52ccc501c02aeb068d2eb4f119ef6f0c2b6a/Zend/zend_execute_API.c#L1058

Joomla component function deprecated

I am using a Joomla component com_fabrik but though its install successfully. As I try to create form I am getting following error.
Fatal error: Call to a member function setId() on a non-object in C:\xampp\htdocs\sankalpJoomla\administrator\components\com_fabrik\models\form.php on line 108
When I searched for code in file I got.
$feFormModel->setId($this->getState('form.id'));
I searched that function is deprecated. is their any other option to sort out problem?
While it may be that the function is deprecated, the error you're getting isn't related to that (at least not directly). What is happening is $feFormModel isn't an actual object, and because of that it has no memeber functions. So when setId() is being called from it, this error is being thrown.
The likely cause is some sort of incompatibility between this component and the version of Joomla you're using.

Categories