Category Archives: PHP

Error: call-time pass-by-reference has been removed

This error may occur when PHP is upgraded to version 5.4 of PHP:
If a function (or class) is used in this way, a PHP Fatal error will result :
foo(& $var);
In fact, that’s what’s going to happen in PHp5.3, but it’s just going to Deprecated.

// Right
function myFunc(&$arg) { do something... }
 
myFunc($var);//Call myFunc
 
//Wrong
function myFunc($arg) { do something... }
 
myFunc(&$arg);//Call myFunc

Mac PHP Fatal error: Class ‘Memcache’ not found

I’ve had this weird problem developing PHP Memcache these days. The Memcache environment was installed successfully but the running code always reported an error

$mem = new Memcache();
$mem->connect('127.0.0.1',11211);
$mem->set("foo","3",0,10);
echo $mem->get("foo");

Running tips PHP Fatal error: Class ‘Memcache’ not found in/Users/XXXXXXXXX/demo/index. The PHP on line 9
Finally, using baidu, Google and their own various experiments finally found the cause of the problem:
code did not find the corresponding memcache.so file

1, install memcache

brew search memcache


Find memcache (note: not memcached) that corresponds to the PHP version installed on your computer.
is installed using brew

brew install php56-memcache

When the installation is complete, the php56-memcache installation directory will be viewed

2, configure php.ini
add at the end of php.ini

extension_dir = /usr/local/Cellar/php56-memcache/2.2.7
extension = memcached.so

Finally, rerun it, and you’ll see the magic: it worked

PHP error in Windows: class’ mysqli ‘not found

For example, we have access to mysql through the API provided by PHP extension Mysqli. The error report is: Class ‘mysqli’ not found. The reason for this error is that PHP was unable to load the dynamic library php_mysqli.dll. The solution is to configure the relevant variables so that the program finds the location.
By default php_mysqli. DLL is existing in the PHP installation directory under ext directory:

The first thing we need to do is to modify the PHP configuration file. The configuration file in Windows is in php.ini under the PHP installation directory. If not, you can make a copy through PHp.ini-Development. We found one of them; Extension =php_mysqli.dll, remove the semicolon at the beginning to allow the configuration to take effect. This means that you can use the MySQli extension.

In general, this is fine, but our configuration file PHp.ini will not take effect if our system does not configure the environment variable PHPRC. In order for php.ini to take effect, we need to configure the environment variable PHPRC, which specifies the PHP installation directory.

After configuring the environment variables, we can restart the Apache server. We can verify our PHP-related information by using phpInfo (). First, the Configuration File is in the Loaded Configuration File, not “none”, but php.ini under the PHP installation directory.

The second is that the mySQli extension appears in the middle of the page. If one of the above two steps is missing, this part will not be displayed. When we call the MYSQli API in our PHP code, we will report an error:
said that php_mysqli.dll from ext in the PHP installation directory should be copied to C:\Windows\ System32. This is because php.ini has not taken effect, and php.ini should be copied to C:\Windows directory.
Next, we can query the emP table ID and name in the mysql database test through a program, the code is as follows:

<?php
$servername = "127.0.0.1";
$username = "root";
$password = "root";
$dbname = "test";

$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connect Fail " . $conn->connect_error);
}

$sql = "SELECT id, name FROM emp";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - name: " . $row["name"]. "<br>";
    }
} else {
    echo "0 output";
}
$conn->close();

We visited the PHP file on the page and got the following results:

A simple mysqli application and the problem of mysqli extension are solved.

Configure: error: Cannot find libz error appears when brew installs php70

This article from the PHP ecshop secondary development blog, please be sure to keep this from http://phpecshop.blog.51cto.com/6296699/1883448

According to the tutorial “New Installation of Mac OS Sierra (10.12) and using HomeBrew to install ZSH + MNMP (Mac + Nginx + Mysql + Php) Development environment”, there was an error in using BREW to install PHP70 on the Mac.

brew install php70 --with-debug --with-gmp --with-homebrew-curl --with-homebrew-libressl --with-homebrew-libxml2 --with-homebrew-libxslt --with-imap --with-libmysql --with-mysql

Error message:

configure: error: Cannot find libz

If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):
https://github.com/josegonzalez/homebrew-php/issues

/usr/local/Homebrew/Library/Homebrew/utils/github.rb:226:in `raise_api_error': Validation Failed (GitHub::Error)
    from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:184:in `open'
    from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:233:in `issues_matching'
    from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:266:in `issues_for_formula'
    from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:325:in `fetch_issues'
    from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:321:in `issues'
    from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:383:in `dump'
    from /usr/local/Homebrew/Library/Homebrew/brew.rb:133:in `rescue in <main>'
    from /usr/local/Homebrew/Library/Homebrew/brew.rb:31:in `<main>'

Solutions:


$ xcode-select --install


$ brew install php70 --with-debug --with-gmp --with-homebrew-curl --with-homebrew-libressl --with-homebrew-libxml2 --with-homebrew-libxslt --with-imap --with-libmysql --with-mysql

Fixed

Reference link:
http://stackoverflow.com/questions/39442552/5-boxen-errors-when-running-boxen-our-boxen

PHP Error Object of class mysqli could not be converted to string in

Write a PHP encountered an error: the Object of the class mysqli could not be converted to a string
An object of class mysqli_result cannot be converted to a string
Check the code:

    function query($sql){
        echo $sql;
        $query = mysqli_query(self::$con,$sql)or die(mysqli_error(self::$con));
    
        return $query;
    }

Mysqli_result is returned by mysqli_query, so the error should be on the return value.

You cannot directly output an object as a string in PHP5 above.
So just change the type of the return value.

    function query($sql){
        echo $sql;
        $query = mysqli_query(self::$con,$sql)or die(mysqli_error(self::$con));
        return  mysqli_fetch_array($query);
        //return $query;
    }

Returns as an array with the mysqli_fetch_array() function.

 

composer Failed to decode response: zlib_decode(): data error

Composer error problem

Failed to decode response: zlib_decode(): data error
Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info

The cause of this error is usually the network.
The solution
Composer page provides a degraded mode solution. If we have ipv6 on we need to uncheck ipv6.

php_network_getaddresses: getaddrinfo failed (How to Fix)

When calling an external service request, PHP addresses: getaddrinfo failed: Name or Servicenot Known with an error:The reason:
PHP host cannot connect to DNS server

Analysis: such as the services you access request is www.leyangjuntestxxxx.com

You can first ping or Telnet the domain name to see if it is accessible, if it is responsive

Failure to ping indicates that your service is now connected to a problematic DNS server

General solutions:

One: It is necessary to check whether the remote host of the request is in /etc/hosts of the native host

Two: the need to check the rules of the firewall, is not intercepted by the response

Three: You can manually bind host in the /etc/hosts file

php Error: mail() Failed to connect to mailserver at “localhost” port 25

When there is a:

warning: mail() [
function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in E:\TOOL\Apache\htdocs\rzchina_beta\club\includes\mail.inc on line 193.

Unable to send e-mail. Please contact the site administrator if the problem persists.

or appear:

mail(): SMTP server response: 550 5.7.1 incapable to relay for error.

solution:

install IIS built-in SMTP, right click on the SMTP virtual server, and set the following Settings in the popup properties window:

click the access TAB, then click relay, click add out of the popup window, then select the single computer, add IP address to 127.0.0.1. And then make sure you go all the way back. SMTP Server Response: 550 5.7.1 incapable to relay for… The error)

test it out:

< ?php

mail(“[email protected]”,” test “,” test if received “);

?>