手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表分类:PHP

Sablog-x 1.6升级支持PHP8成功

 发现从PHP7.4升到PHP8后,就一个地方,那就是 get_magic_quotes_gpc 这个函数。报错信息是:PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function get_magic_quotes_gpc()。

方法未定义?看了下文档,原来从7.4.1开始就已经不再支持了,而且永远返回False,在PHP8中彻底移除,仅此而已,于是乎。。。。
在 include/common.php 文件中,在调用 get_magic_quotes_gpc上面加了一段 :
if(!function_exists('get_magic_quotes_gpc')){
    function get_magic_quotes_gpc(){
        return false;
    }
}
然后,一切正常,所以我就不再上传新包了。(页面详情可能有不正常的情况,是因为我在上一页下一页的时候。$article[articleid]上没有加单引号,进入后台在模板管理 default/show.php 搜到 57行,下一篇的链接就是 ,调整一下即可)
 
----
改完后才发现,问题很多啊。。。比如 global.php的296行,$article[image] ,这种代码太多了。。。。估计得一点点改了,php4的后遗症啊。
 
----
只能说解决了95%的问题,其它的只能遇到后慢慢改了。。。我也不可能一个个的去定义:define('image','image');。当然 这样就彻底解决了,只是有点2
 
 

Error in render: "Error: Ziggy error: 'project' parameter is required for route 'projectPage'."

 在使用Ziggy的时候,偶尔会报类似的错误:

Error in render: "Error: Ziggy error: 'project' parameter is required for route 'projectPage'."。
仔细看出错的路由,往往都是有必要参数的,比如Route::any('/test/{user:uuid}',[UserController::class,'test'])->name('test')
象这种路由,如果在JS中直接获取route().current()来获取当前路径并显示,那肯定就会报错。因为current()方法是将参数和路由一并显示出来。
route(route().current())这样的报错怎么处理呢?
其实,只要加上params参数就行了,例如:route(route().current(),route().params).toString(),为什么会有这么妖的写法?是因为在公众号的网页里,如果你要用jssdk,就必须是当前URL,如果不正确,获取的签名也就可能是失败的,因此,才想到用这个恶心的方法。当然你也可以用location.href...
 
 

aliyun composer 镜像可能有问题

 好几次遇到阿里云的镜像更新有问题了,明明某个库有了最新版,但阿里云就是报版本不存在。今天又出现了这样的情况,安装laravel-zero的时候,require-dev中有个laravel/pint ^1.2,直接就报了

 
  Problem 1
    - Root composer.json requires laravel/pint ^1.2, found laravel/pint[dev-main, v0.1.0, ..., v0.2.4, v1.0.0, ..., v1.1.3] but it does not match the constraint.
 
问题是这个laravel/pint 的github上,1.2的release是 9月13日啊。(laravel/pint: Laravel Pint is an opinionated PHP code style fixer for minimalists. (github.com))。
 
由于之前也遇到过这个问题,当时是unset掉 aliyun镜像,换成了官方镜像,但确实是慢,所以我就看了一眼其他镜像,比如以前常用的https://packagist.phpcomposer.com,在国内没有其他镜像的时候,它做了很大的贡献,然而也太不稳定了。直接报:

Problem 1 - Root composer.json requires laravel-zero/framework, it could not be found in any version, there may be a typo in the package name. Problem 2 - Root composer.json requires nunomaduro/termwind, it could not be found in any version, there may be a typo in the package name. Problem 3 - Root composer.json requires laravel/pint, it could not be found in any version, there may be a typo in the package name. Problem 4 - Root composer.json requires mockery/mockery, it could not be found in any version, there may be a typo in the package name. Problem 5 - Root composer.json requires pestphp/pest, it could not be found in any version, there may be a typo in the package name. Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details. - It's a private package and you forgot to add a custom repository to find it Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

看来,已经多年没有更新过了,真可惜了。
最后在这里找到了:国内 PHP Composer 镜像列表 - 腾讯云开发者社区-腾讯云 (tencent.com),列表中的那些镜像,象最后的安畅网络的,网址都崩了。所幸,腾讯的还能用。
打开:腾讯软件源 (tencent.com),搜到composer,看一下帮助(真简单就两句话),一句教你配置,一句教你下载。
配好之后,composer u,完成。记录一下
 
 
1、阿里:composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
2、腾讯:composer config -g repos.packagist composer https://mirrors.tencent.com/composer/
3、清除:composer config -g --unset repos.packagist
 
带 -g 的是全局的,不带  -g,就是当前项目了。
 

 

predis扩展数组和对象的存入

PHP有不少Redis库,比如pecl的Redis库(phpredis),就是直接自带了数组的存取和读出,因为他在存储和读出的时候自动序列化了。象是象predis就不行,如果你直接存一个数组去,那么它就会报warning,同时存一个Array到指定的KEY上。

但是predis允许你封装自定义的redis方法。比如jsonset/jsonget,这时候你利用这些自定义的方法来获取或写入数组即可。(基于Laravel,其他的也一样,其他参考:Setting arrays · Issue #136 · predis/predis (github.com))

只是官方的Issue中 【Predis\Profile\ServerProfile:】已经不存在了,要换成【Predis\Profile\Factory】,其余可以复制

----

基于Laravel的话,上述的数组可以放到config里,就啥出不用配置了~~

PHP代码
  1. if (!function_exists('yredis')) {  
  2.     class StringSetJson extends Predis\Command\StringSet  
  3.     {  
  4.         protected function filterArguments(array $arguments)  
  5.         {  
  6.             $arguments[1] = json_encode($arguments[1]);  
  7.             return $arguments;  
  8.         }  
  9.     }  
  10.   
  11.     class StringGetJson extends Predis\Command\StringGet  
  12.     {  
  13.         public function parseResponse($data)  
  14.         {  
  15.             return json_decode($data, true);  
  16.         }  
  17.     }  
  18.   
  19.     class StringSetPhp extends Predis\Command\StringSet  
  20.     {  
  21.         protected function filterArguments(array $arguments)  
  22.         {  
  23.             $arguments[1] = serialize($arguments[1]);  
  24.             return $arguments;  
  25.         }  
  26.     }  
  27.   
  28.     class StringGetPhp extends Predis\Command\StringGet  
  29.     {  
  30.         public function parseResponse($data)  
  31.         {  
  32.             return unserialize($data);  
  33.         }  
  34.     }  
  35.   
  36.     /** 
  37.      * 这个方法是为了读redis,但是不含prefix 
  38.      * @param  string  $connection 
  39.      * @return RedisManager 
  40.      */  
  41.     function yredis()  
  42.     {  
  43.         try {  
  44.             $redis = app('yredis');  
  45.         } catch (Exception $e) {  
  46.             app()->singleton('yredis'function ($app) {  
  47.                 $config = $app->make('config')->get('database.redis', []);  
  48.                 unset($config['options']['prefix']);  
  49.                 if(env('REDIS_CLIENT') == 'predis'){  
  50.                     $config['options']['profile'] = function ($options$option) {  
  51.                         $profile = \Predis\Profile\Factory::getDefault();  
  52.                         $profile->defineCommand('jsonset''StringSetJson');  
  53.                         $profile->defineCommand('jsonget''StringGetJson');  
  54.                         $profile->defineCommand('phpset''StringSetPhp');  
  55.                         $profile->defineCommand('phpget''StringGetPhp');  
  56.                         return $profile;  
  57.                     };  
  58.                 }  
  59.                 return new \Illuminate\Redis\RedisManager($app, \Illuminate\Support\Arr::pull($config'client''phpredis'), $config);  
  60.             });  
  61.             app()->bind('yredis.connection'function ($app) {  
  62.                 return $app['yredis']->connection();  
  63.             });  
  64.             $redis = app('yredis');  
  65.         }  
  66.         return $redis;  
  67.     }  
  68. }  
因为laravel的默认config会带 prefix,所以写一个简单的,其实就是为了在写数据的时候不加     prefix 。。。

 

 

PHP 8.1 features a new type for return values: never.

如题

 
比如,你定义了一个方法,
PHP代码
  1. function test():never {  
  2.      exit(1);  
  3. }  

在其他方法使用的时候, 
PHP代码
  1. doSomething(){ 
  2.     test() ; 
  3.     echo 123;
  4. }  

在IDE里,会提示这个echo 123;的错误是unreachable

 
原来phpstorm支持:#[NoReturn] 这个注释,但现在有语法级的支持,则变得更舒服。
----
然而,现在线上用的还是PHP7.3。连fn=> 这个功能都用不了。还有就是对于对象的操作$a?->b?->c也用不了。。。
只能接着忍,Laravel 9最低要8.0了,估计可能会强制更新了
Records:64112345678910»