Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug,分页 #500

Open
yuyachong opened this issue Sep 9, 2023 · 12 comments
Open

bug,分页 #500

yuyachong opened this issue Sep 9, 2023 · 12 comments

Comments

@yuyachong
Copy link

frameword:8.0.2
orm:3.0.13

使用分页paginate方法,在控制器使用return json() 可以被正常对象输出
如果将 json()封装为 自己的方法return myJson(),则分页会以html输出

在tp6上没有这个问题

@yuyachong
Copy link
Author

Paginator类中,jsonSerialize()方法在tp6上会被执行, 在tp8中被跳过了,问题出在这里,不知道为何跳过了

@yuyachong
Copy link
Author

刚无意间调整了 方法参数的位置, 发现在myJson($data, $msg, $code) 只要$data参数放第一位就可以自动toArray,
在tp6是可以随意摆放位置的,老大看看怎么回事修复一下

@augushong
Copy link
Contributor

看下你myjson代码

@yuyachong
Copy link
Author

yuyachong commented Sep 13, 2023

看下你myjson代码

function myJson(int $code, string $msg, int|array|string $data): Json { return json([ 'code' => $code, 'msg' => $msg, 'data' => $data ]); }

我刚测试了 $data 在tp8下必须放第一位才会自动toArray,TP6没有这个问题

@augushong
Copy link
Contributor

你是说数组里的data放到数组开头,还是参数里的data放到参数开头。

@yuyachong
Copy link
Author

错误:
myJson(int $code, string $msg, int|array|string $data)

正常:
myJson($data, int $code, string $msg)

刚发现,$data还不能固定类型,不然依然不能toarray

@augushong
Copy link
Contributor

你可以在这个文件这一行
vendor\topthink\framework\src\think\Container.php
385行打印一下反射出来的参数,对比一下你调整位置之后,是不是一样的,如果是一样的,那跟tp就没啥关系。
有可能是传参不对
图片

@augushong
Copy link
Contributor

或者是349行的获取到得args。

@augushong
Copy link
Contributor

我试了一下,没有复现出你说的情况。要不你更新下php的版本试试,之前的php8之后的版本,调整过反射相关的bug。

@yuyachong
Copy link
Author

我试了一下,没有复现出你说的情况。要不你更新下php的版本试试,之前的php8之后的版本,调整过反射相关的bug。

找到问题所在了,不是参数位置问题, 是类型问题: 之前是 int|string|array, 但是不能这么写,只有单独使用array或者mixed才可以

@augushong
Copy link
Contributor

应该也不是这个问题,我用你给的myjson测试,没有问题。可以再找找。mixed本身就能覆盖int、string等,不要紧的。

@yuyachong
Copy link
Author

应该也不是这个问题,我用你给的myjson测试,没有问题。可以再找找。mixed本身就能覆盖int、string等,不要紧的。

好的,谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants