沉冰浮水

沉冰浮水

做最终到的事,成为最终成为的人!
github
bilibili
mastodon
zhihu
douban

"Reproduction of Various Error Messages in 'Waterhole' Z-BlogPHP"

Strictly speaking, not all errors are unique to Z-BlogPHP;

Also, the title here is "Reproduction", demonstrating why this type of error occurs with the simplest example. Whether beginners can understand it and whether it can help solve actual problems... ummm

Monthly subscription of 59.3, answering various questions based on mood... mainly about Z-Blog.

HelloZBlog "Plugin Development Demonstration" - Z-Blog Application Center:

https://app.zblogcn.com/?id=18072

In zb_users\plugin\HelloZBlog\include.php, there is a HelloZBlog_debug() function, where you can test the reproduction of various errors below.


Array and string offset access syntax with curly braces is no longer supported

The direct translation of offset access is "偏移访问" in Chinese, which corresponds to the concept of "(array) index";

syntax means "语法" in Chinese, for example, in PHP and JavaScript, both single quotes and double quotes can be used to express ordinary strings, but when it comes to "variable parsing/template strings," they have their own "syntax rules";

curly braces means "大括号" in Chinese;

no longer supported means "不再支持" in Chinese;

// Correct
$arr = array(1,2,3);
echo $arr[0];
// die();

// Incorrect
$arr = array(1,2,3);
echo $arr{0}; // Array or string offset access with curly braces deprecated in PHP 7.4. Targeting PHP 8.1.0.
// die();

The editor's syntax check will prompt:

The "curly brace" form of "array or string index" has been deprecated in "PHP 7.4," and then "Targeting PHP 8.1.0";

So how should we translate this "Targeting"... I am currently using 7.4 myself, and in reality, curly braces do not cause any errors. This error only occurs when using PHP 8, as discussed in various discussions.


Trying to access array offset on value of type null

// Correct
$var = array(0);
echo $var[0];
// die();

// Error
$var = null;
echo $var[0];
// die();

Function name must be a string

// Correct
$var = "fnTest"; // Assuming fnTest() function exists
echo $var();
// die();

// Error
$var = 1024;
echo $var();
// die();

Call to undefined function fnTest()

To execute the example $var = "fnTest"; correctly, it needs to be defined as follows:

function fnTest()
{
  return "test";
}

Call to a member function fnTest() on bool

$obj = true;
$obj->fnTest();
// die();

Array to string conversion

// Correct, perform conversion or additional processing before outputting
$arr = array(0, 1, 2);
echo implode(", ",$arr);
// die();

// Error, output directly as string
$arr = array(0, 1, 2);
echo $arr;
// var_dump("$arr"); // Another way to make the error
// die();

Reference:

Solution to PHP error "Array to string conversion": https://blog.csdn.net/zeroking_vip/article/details/87960319 "CSDN Few Useful Contents"

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.