PHP warning cannot use a scalar value as a array solution _php tips

Source: Internet
Author: User
Tags scalar
See the error log in PHP for some of these tips:

[27-aug-2011 22:26:12] PHP Warning:cannot use a scalar value as a array in/www/hx/enjoy.php in line 14
[27-aug-2011 22:26:18] PHP Warning:cannot use a scalar value as a array in/www/hx/enjoy.php in line 14

Check the source program, which is probably the following:
Copy Code code as follows:

$arr _hx = $mem->get (' HX ');
if (! $arr _hx) {
$arr _hx[' a '] = ' B ';
$mem->set (' HX ', $arr _HX);
}

It's basically clear that when $mem->get doesn't get a value, it returns false, at which point the $ARR_HX is False, the Boolean, and then it is used as an array, resulting in the hint. In fact, a variable does not define a situation, add a sentence before the assignment $arr _hx = array () to solve the problem.

Looked up, like the following description:
Reference
What you need to be aware of is type conversions:
If a variable name (such as a) has been defined as a non-array type, such as Integer, then a can be converted to floating point, string (or even object type), but not an array, that is, a[0]=1; it is wrong, PHP will quote such a warning " Cannot use a scalar value as a array ". Even if a is defined as a one-dimensional array, it cannot be converted to a high-dimensional array.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.