正如标题所说,这个错误发生在我身上。我搜索互联网并发现 https://github.com/processwire/processwire-issues/issues/1286#issuecomment-738880424
原始代码:
function exception_error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
}
Run Code Online (Sandbox Code Playgroud)
我只是更改最后一个参数并将其设为可选,如下所示:
function exception_error_handler($errno, $errstr, $errfile, $errline, $errcontext=[]) {
}
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么这个参数变成可选的?
从 PHP 7.4 迁移到 PHP 8.0,我遇到了一些代码抛出警告的问题。代码有效,但我想找出问题所在。PHP 7.4 中没有警告。以下是警告:(已修改以将我的信息从错误中删除)
PHP 警告:XML::open():参数 #1 ($parser) 必须通过引用传递,值在 .../classes/xml_5.php 第 89 行给出
PHP 警告:XML::open():参数 #1 ($parser) 必须通过引用传递,值在 .../classes/xml_5.php 第 89 行给出
PHP 警告:XML::open():参数 #1 ($parser) 必须通过引用传递,值在 .../classes/xml_5.php 第 89 行给出
PHP 警告:XML::data():参数 #1 ($parser) 必须通过引用传递,值在 .../classes/xml_5.php 第 89 行给出
PHP 警告:XML::close():参数 #1 ($parser) 必须通过引用传递,值在 .../classes/xml_5.php 第 89 行给出
PHP 警告:XML::open():参数 #1 ($parser) 必须通过引用传递,值在 .../classes/xml_5.php 第 89 行给出
(他们继续做同样的事情)
代码:
function __construct(){
$this->parser = xml_parser_create();
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'open', 'close');
xml_set_character_data_handler($this->parser, 'data');
} …Run Code Online (Sandbox Code Playgroud) 我必须将基于 codeigniter 3 的 CRM 从 PHP 版本 7.4 迁移到版本 8.*。但当我探索 codeigniter 3 与 php 8 的兼容性时,我发现很少有答案说它不兼容。
但这个答案已经很旧了(大约 1 到 2 年)。两个参考是: Codeigniter 论坛 codeigniter github
所以,作为参考是旧的。Codeigniter 3 目前支持 php 版本 8 吗?
我一直在寻找一些关于 的最佳值的指南opcache.jit_buffer_size。建议的值最多为 256M(例如https://php.watch/versions/8.0/JIT#jit-opcache.jit_buffer_size)甚至 500M(https://medium.com/@edouard.courty/make-your- php-8-apps-twice-as-fast-opcache-jit-8d3542276595)。但(在我看来)他们似乎只是任意选择的。
但是,我找不到关于如何选择该值的太多解释。“深入 JIT”一文 ( https://php.watch/articles/jit-in-depth#jit-ideal ) 提供了一些线索。
RFC https://wiki.php.net/rfc/jit也没有帮助。
我想答案是:在您的环境中进行一些基准测试并选择最佳的缓冲区大小。
有人对这个话题有一些想法吗?或者也许知道一个好的参考资料?
在 php-8 及更早版本中,以下代码有效
class Foo {
public function __construct(string $string = null) {}
}
Run Code Online (Sandbox Code Playgroud)
但是在php-8中,随着属性提升,它会抛出错误
class Foo {
public function __construct(private string $string = null) {}
}
Run Code Online (Sandbox Code Playgroud)
致命错误:不能使用 null 作为字符串类型参数 $string 的默认值
不过,使字符串可为空是可行的
class Foo {
public function __construct(private ?string $string = null) {}
}
Run Code Online (Sandbox Code Playgroud)
那么这也是一个错误还是有意的行为?
假设我有以下属性声明
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Route
{
public function __construct(
public string $path,
public ?string $method = null,
public ?string $alias = null
)
{}
}
Run Code Online (Sandbox Code Playgroud)
我在一些控制器方法中使用它,如下所示:
class Controller
{
#[Route('/index/')]
#[Route('/home/', alias: 'home')]
public function index()
{
...
}
#[Route('/create/', 'POST')]
public function create(Request $request)
{
//...
}
}
Run Code Online (Sandbox Code Playgroud)
我如何获取这些属性实例并读取它的属性?
我已经更改了 Symfony 项目的配置,以在实体中使用 PHP 属性和 Doctrine。我对此感到非常高兴并想尝试一下。
我已将我的doctrine.yaml从更改annotation为attribute
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
Run Code Online (Sandbox Code Playgroud)
并在我的实体中使用属性
#[ORM\Entity(UserRepository::class)]
class User implements UserInterface
{
#[ORM\Id()]
#[ORM\GeneratedValue()]
#[ORM\Column(type: "integer")]
private ?int $id;
#[ORM\Column(type: "string", length: 180, unique: true)]
private ?string $email;
#[ORM\Column(type: "json")]
private array $roles = [];
}
Run Code Online (Sandbox Code Playgroud)
有了这个配置,我的php bin/console do:sc:up -f工作就很好。
但是当我尝试生成一个新实体时,php bin/console make:entity出现以下错误:
[错误] make:entity 仅支持注释映射,但 App\Entity\Toto 类使用不同的格式。如果您希望此命令生成属性和 getter/setter 方法,请添加映射 …
我刚刚将 Mac M1 更新到 Big Sur 11.5.2,VSCode 中的某些内容似乎已损坏。我无法使用已安装的最新 home-brew php。
在 VSCode 中,它指向 /usr/bin/php ,这是用 php 构建的 Mac,这不是我在 home-brew 中使用的那个。我尝试了一切并改变了路径,但仍然是同样的事情。
我检查了一个与我类似的问题,它建议使用我已经在做的 Homebrew,所以我不确定我在这里做错了什么。
我正在 VSCode 终端中运行 PHPUnit 测试,但收到以下错误:
/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
/usr/bin/php declares an invalid value for PHP_VERSION.
This breaks fundamental functionality such as version_compare().
Please use a different PHP interpreter.
/Users/themyth/App/Sites/MapFramework/map ->
Run Code Online (Sandbox Code Playgroud)
但是,当我通过转到同一文件夹在 Mac 终端中运行相同的操作时,它运行得很好:
/Users/themyth/app/Sites/MapFramework/Map -> ./vendor/bin/phpunit tests
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
Runtime: PHP 8.0.9
Configuration: /Users/themyth/App/Sites/MapFramework/Map/phpunit.xml
...R 4 / 4 (100%)
Time: 00:00.004, Memory: …Run Code Online (Sandbox Code Playgroud) 这是我的泊坞窗文件:
FROM php:8.0-fpm-buster
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
git \
curl \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
jpegoptim optipng pngquant gifsicle \
libonig-dev \
libxml2-dev \
zip \
sudo \
unzip \
npm \
nodejs \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 vultr 的 Ubuntu 22.04 服务器上安装 LEMP。\n我可以安装 Nginx sudo apt install -y nginx- 没问题。
但是当我尝试通过运行这些命令安装 php8.0 时
\nsudo apt install software-properties-common\nsudo add-apt-repository ppa:ondrej/php\nsudo apt-get update\nRun Code Online (Sandbox Code Playgroud)\n我不断收到错误The repository 'https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy Release' does not have a Release file.
sudo add-apt-repository ppa:ondrej/php这是运行命令后得到的结果
root@ubuntu:~# sudo add-apt-repository ppa:ondrej/php\nPPA publishes dbgsym, you may need to include 'main/debug' component\nRepository: 'deb https://ppa.launchpadcontent.net/ondrej/php/ubuntu/ jammy main'\nDescription:\nCo-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of …Run Code Online (Sandbox Code Playgroud) php-8 ×10
php ×7
apple-m1 ×1
attributes ×1
class ×1
codeigniter ×1
doctrine-orm ×1
gd ×1
jit ×1
laravel-8 ×1
libjpeg ×1
nginx ×1
nullable ×1
opcache ×1
optimization ×1
phpunit ×1
symfony ×1
ubuntu ×1
ubuntu-20.04 ×1
warnings ×1
xml ×1