gpt4 book ai didi

PHP:面向对象的代码 - 找不到类 'x',但有

转载 作者:行者123 更新时间:2023-12-04 16:59:20 24 4
gpt4 key购买 nike

我在包含 CryptoGuard 时遇到问题,但也许我的面向对象代码有问题,因为我是新手。

require_once('CryptoGuard.php'); // = https://github.com/CoreProc/crypto-guard/blob/master/src/CryptoGuard.php

$passphrase = 'my_private_key';
$cryptoGuard = new CryptoGuard($passphrase);
$stringToEncrypt = "private string";
$encryptedText = $cryptoGuard->encrypt($stringToEncrypt);
echo $encryptedText;

CryptoGuard 的简单使用示例: https://github.com/CoreProc/crypto-guard (与我使用的一样,但我不使用 Composer,所以我只是复制了 CryptoGuard.php)。

没有 php 错误,但是带有 cryptoGuard 的部分破坏了页面(停止加载任何东西,那里没有 $encryptedText 回显)。

最佳答案

您的问题是 Namespace . CryptoGuard 使用 Coreproc\CryptoGuard ;

所以你的代码应该是

require_once('CryptoGuard.php'); // = https://github.com/CoreProc/crypto-guard/blob/master/src/CryptoGuard.php

$passphrase = 'my_private_key';

//Not missing the Namespace here
$cryptoGuard = new \Coreproc\CryptoGuard\CryptoGuard($passphrase);
$stringToEncrypt = "private string";
$encryptedText = $cryptoGuard->encrypt($stringToEncrypt);
echo $encryptedText;

或者,如果您在脚本的开头编写,您提供的代码将起作用:
use \Coreproc\CryptoGuard\CryptoGuard;

关于PHP:面向对象的代码 - 找不到类 'x',但有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28700653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com