I am trying to use MemcachePool in my code, it reports the following error in PhP:
PHP Fatal error: Class 'MemcachePool' not found in test.php
Here is the code snippet:
$this->mMemcached = new MemcachePool();
$this->mMemcached->addServer(...)
i never heard of MemcachePool - maybe you just wanted to use Memcache (thats where addServer() can be found)? in that case, just change your code to:
$this->mMemcached = new Memcache();
$this->mMemcached->addServer(...);
if this isn't what you're looking for, MemcachePool has to be a third party extension that hasn't been installed or a custom (wrapper)-class wich you forgot to include.
Related
I'm coming back to PHP after many years and am running into a bit of an odd problem. I'm running PHP 7.1.7 on Windows and am trying to install and utilize the maclof/kubernetes-client library via Composer. I have the following simple code snippet to test things out:
<?php
require __DIR__ . '/vendor/autoload.php';
use Maclof\Kubernetes\Client;
$path = realpath(__DIR__ . '/kubeconfig.yaml');
// this works (when fully qualified)
$config = Maclof\Kubernetes\Client::parseKubeconfigFile($path);
// but this doesn't
$client = new Client($config);
?>
As you can see, when I access the static method parseKubeconfigFile using the fully-qualified class name (Maclof\Kubernetes\Client), this works. But when I try to just use the shorter name of Client, it doesn't work. Even class_exists("Client") returns false. It's as though PHP is outright ignoring the use statement, and I don't know why.
What am I missing? Is there some weird php.ini directive that governs use statements? Or is there some wacky bug in this specific version of PHP? I'm pulling my hair out right now trying to understand why this doesn't work.
My website had a older version of wordpress. Recently I upgraded it to the latest version. After that my php code what I write in the editor is keep getting disabled.
The old page which has php code in ti still works. Although in the editor the php codes are disabled. But if I try to save that it stops working. So i cannot update those page. And also I cannot create new page with php code in it
Exec-PHP plugin is installed.
If I write
<?php echo $c; ?>
It converts into
<!--?php echo $c; ?-->
How to fix that
attached image for better understanding.
Another way, which I don't quite recommend, is to follow this direction:
https://wordpress.org/support/topic/exec-php-to-work-in-php-7-needs-this/
This is basically updating the actual plugin, which will surely be overwritten by their next update.
This plugin requires a number of changes to work with php 7.
In exec-php.php
$GLOBALS[‘g_execphp_manager’] =& new ExecPhp_Manager();
must be changed to
$GLOBALS[‘g_execphp_manager’] = new ExecPhp_Manager();
In includes/manager.php from line 36
change each =& to =
In includes/admin.php lines 53,56,57,63,64,79 change =& to =
In includes/cache.php line 22,39 change =& to =
In includes/ajax.php line 64 change =& to =
I don't know about the plugin you use for this. However, I use xyzscripts for the same cause. It creates short-codes for me to use.
Here is an example:
Create your PHP code and get a Tracking Name.
You will then get your short-code as below, note the Tracking Name.
I personally think this is the best way as it allows re-usability and centralized location to update all your scripts.
XYZ WP PHP Code Download and Documentation
Thank you all for responding.
Apparently I find the solution by installing the Classic Editor plugin
https://en-gb.wordpress.org/plugins/classic-editor/
It prevents disabling the php code.
If you are facing similar problem you can try this one
Fatal error: Call to undefined method Exception::getClass()
Simply! You are calling a function which is not available
I assume it's OpenCart error. It might be seen after new extension is added or after OC version update as they recently changed some file paths.
The URL probably looks like:
http://example.com/index.php?route=exampleA/exampleB/exampleC
You need to correct the route. Start adding extension in front. It works in some cases.
The updated URL would be:
http://example.com/index.php?route=extension/exampleA/exampleB/exampleC
If that works fine, you need to correct path in your extension source. If not keep searching in documentation.
If you work with cart.php it was moved from system/library/cart.php to system/library/cart/cart.php together with some other files. Good luck and try to give us more details in the future.
According to their PHP Packagist repository page
https://packagist.org/packages/maxmind-db/reader
the following code is all I need to get the reader to work. PHP doesn't seem to like the use MaxMind\Db\Reader;line. Any clue on how to fix this so it uses the reader.
require_once 'vendor/autoload.php';
use MaxMind\Db\Reader;
$reader = new Reader('GeoIP2-City.mmdb');
print_r($reader->get($_SERVER['REMOTE_ADDR']));
$reader->close()
Okay the solution I figured out is that anything that uses the keyword [use] need to be first in the PHP document; e.g. API.
I'm new to PHP and Im playing around with some code to see what i can learn/do. I have a simple little project where I am connecting to a mysql db and displaying the records of a table.
When I put all my code in one file, everything runs smooth, as soon as I try to put a chunk of code in a separte PHP file and use an include or require_once I get the error Assigning the return value of new by reference is deprecated in...PEAR\config.php yadda yadda
I've done some research and I understand that passing an object by reference (&obj) is no longer acceptable in PHP 5, that's fine, but no where in my code do I have an ampersand, and again, it all works fine if it's all in the same .php file. So i figure i might be doing something wrong with my includes or something.
This is the file that 'does the work' that i am calling from my main page with a require_once
include '/config.php';
// Open the database connection
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
//Define and run the query
$query = "SELECT * FROM wp_posts";
$result = mysql_query($query);
echo mysql_error();
//Close the db connection
mysql_close();
echo "<table><tr><td>Post Title</td><td>Post Status</td><td>Post Date</td></tr>";
//Loop through result set and display data
while($tdata=mysql_fetch_array($result))
{
echo "<tr><td>$tdata[post_title]</td><td> $tdata[post_status]</td><td> $tdata[post_date]</td></tr>"; // name class and mark will be printed with one line break
}
echo "</table>";
Anyways, I know my code isn't beautiful, Im still trying to figure it all out. Thanks for any help you can provide.
Additional Information:
Ok, I know I'm a complete noob on this include stuff, and i apologize. Cant quite wrap my head around it all yet. But here's some additional info. Here is the full text of the error message I'm receving (NOTE: My code still runs and my table DOES still display)
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 80
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 166
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config\Container.php on line 111
Again, I'm using netBeans as my IDE, so in my Netbeans i went to Tools-Options and went to PHP and set C:\xampp\php\PEAR as the Global include path (Whatever the heck that means, but nonetheless it seemed like a good idea).
I guess if my include path is set right (/xampp/php...) then why am I still receiving the error. Grrr. Thanks for all your help guys.
It's the third party library you're using that's causing the problem, it's out of date and is using such things as returning by reference which are no longer considered good practice. You should upgrade the library in question. From what you've written I'm guessing it's this library. http://pear.php.net/package/Config/redirected
Try running pear upgrade config from the shell.
Your include path might be set in the wrong order.
The script seems to prefer the PEAR include directory over the current working directory.
There are several ways to fix this:
1. use absolute includes
For instance, in your case:
include dirname(__FILE__) . 'config.php'; // pre-PHP 5.3
include __DIR__ . 'config.php'; // PHP 5.3
2. change the include path
To read more about this, see this page in the php.net documentation
Open your config.php and go to line 89 and remove the & after =
from:
"$this->container =& new Config_Container('section', 'root');"
to:
"$this->container = new Config_Container('section', 'root');"
Same goes to line 166.
it is simply pear package error which describes the problem about the assignment. so we can normally replace the assignment of
=& with =
in the given line of the error statement.that will solve our problem.
I had similar problem.The solution is change name of your file. config.php gets a file in pear folder not your config file.
Just run C:\xampp\php\pear-update.bat and restart the Apache server (On Windows macchine).
For linux macchine follow the instuctions of GordonM.