Need Help: Using SolrPhpClient in Drupal - php

I am using SolrPhpClient with Drupal and i want to use drupal as higher-layer user-interface to be able to query and retrieve search results from "apache solr"
I tried to use this example here (http://code.google.com/p/solr-php-client/wiki/ExampleUsage) for testing if drupal works with SolrPhpClient, but i am getting two errors which are presented below
1) Deprecated function: Function split() is deprecated in ApacheSolr_Response->_construct() (line 117 of /var/www/drupal/sites/all/modules/apachesolr/SolrPhpClient/Apache/Solr/Response.php).
2) Warning: htmlspecialchars() expects parameter 1 to be string, array given in eval() (line 80 of /var/www/drupal/modules/php/php.module(75) : eval()'d code).
Does anyone in reddit use SolrPhpClient before ? I have never used PHP so had a difficult time understanding it ?
Any kind of help will be appreciated
Many Thanks

split function is deprecated in PHP 5.3.0. So use explode function instead of split.
http://patelmilap.wordpress.com/2011/09/07/list-of-deprecated-functions-php/
And please tell me what are you passing in htmlspecialchars() function ?
It is used to Convert special characters to HTML entities.
http://php.net/manual/en/function.htmlspecialchars.php

Related

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

I have a problem with an old plugin installed on my Wordpress site. Since I updated my php to php 7.4, I am getting the message saying: "Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior". The error is detected on line 454 of UpdateChecker.php file, which is the following:
$cachedResult = (strpos($pluginPath, $muPluginDir) === 0);
Could anyone please help me to solve the issue? I would really appreciate!
Thanks in advance
Cheers
As you mention the plugin has not been updated you'll need to update it yourself - the line you reference would need to be something like:
$cachedResult = (strpos($pluginPath, (string)$muPluginDir) === 0);
You may also need to search the plugin for any other instances, or at least keep an eye on your error logs for any other updates required.
If the plugin you're using is open source you may wish to submit the fix once you've tested to the package maintainers (if indeed they're still maintaining it at all).

Array to string conversion in Php7

I am trying to execute this code (it was working on php5, now I'am on php7):
$this->links->$data[$te]['attributes']['ID'] = $data[$te]['attributes']['URL'];
But I get this error:
ContextErrorException: Notice: Array to string conversion
Thanks in advance
This is down to the change in how complex variables are resolved in PHP 5 vs 7. See the section on Changes to variable handling here: http://php.net/manual/en/migration70.incompatible.php
The difference is that the expression:
$this->links->$data[$te]['attributes']['ID']
is evaluated like this in PHP 5:
$this->links->{$data[$te]['attributes']['ID']}
and like this in PHP 7:
($this->links->$data)[$te]['attributes']['ID']
See https://3v4l.org/gB0rQ for a cut-down example.
You'll need to amend your code to be explicit, either by using {} as appropriate, or by breaking it down into two lines. In this case, where you've got code that works fine in PHP 5, pick the former, since it will mean the behaviour stays consistent in all versions of PHP.

PHP Pack - Combining two pack codes like perl does

I've been trying to figure out if the PHP implementation of Pack with statements like this.
In perl this works:
pack( 'A4/A*', "Humpty-Dumpty" );
From perl docs:
Combining two pack codes with a slash (/) associates them with a
single value from the argument list. In pack, the length of the
argument is taken and packed according to the first code while the
argument itself is added after being converted with the template code
after the slash.
in php when I try pack something like this getting error:
Warning: pack(): Type /: unknown format code
and pack return only false.
Have Someone same problems? (or custom code/library to resolve this in php)
To support perl like pack definitions I implement preprocessing of the definition.

Eval() Error with eval()'d error

YES. I searched google for any answers.
I am learning php. I am trying to send email using some php code that has this eval line.
eval("job();");
But getting error:
eval()'d code on line 1
Any advice?
Don't use eval(). It's evil.
Assuming job is a function, you can call job() directly.
job();
If job() returns a value, you can assign it to use later, as needed.
$variable = job();
Either call the function directly (if you know the name - judging by your snippet, you do) or, if you don't know what function needs to be called (it depends on a variable value or something, try using call_user_func or similar functions.Also make sure the function exists with function_exists, for example
There's a whole bunch of functions, built into PHP that allows you not to use eval... just spend some time browsing through the docs

php: Why preg_replace_callback does not allow built in php functions, just anonymous user functions?

This does not work, and outputs an empty string:
$check["pattern"] = "correct";
$text = "Could this be correct?";
echo preg_replace_callback($check["pattern"],ucfirst,$text);
Would have been nice to use built in functions. In fact general callbacks do allow built in functions as per http://php.net/manual/en/language.types.callable.php, but not preg_replace_callback. Could be a feature request for php?
Your code should trigger a notice and a warning:
Notice: Use of undefined constant ucfirst - assumed 'ucfirst'
Warning: preg_replace_callback(): Delimiter must not be alphanumeric or backslash
If it doesn't, you seriously need to check your PHP error reporting settings. Fixing the code with the help of the error messages:
$check["pattern"] = "/correct/";
$text = "Could this be correct?";
echo preg_replace_callback($check["pattern"],'ucfirst',$text);
... we get this:
Warning: ucfirst() expects parameter 1 to be string, array given
So using a builtin callback function is working fine. However, as the manual page for ucfirst() explains, the function expects a string, not an array. And, as the manual page for preg_replace_callback() explains:
A callback that will be called and passed an array of matched elements in the subject string.
To sum up: it isn't a sensible feature request, it's a bug in your code ;-)
It works just fine with all functions. The problem is that those functions expect certain parameters. ucfirst expects strings as input, but preg_replace_callback is passing an array of matches.
So... if you have a built-in function whose signature is compatible with a preg_replace callback signature, it works. But no, not all built-in functions have a compatible signature.

Categories