Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Undefined method appears when Component and Model have the same name

Đang mở
#29 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
php
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu với reproducer gồm BasicComponent, Basic model và FakeController, sau đó theo dõi cách resolver phân giải $this->Basic khi component và model có cùng tên. Xác nhận cách xử lý khai báo $uses của controller; được xem là hoàn tất khi phương thức của model được nhận diện mà không tạo ra lỗi undefined-method, kèm theo một trường hợp regression cho ví dụ này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Hi.

Thanks for this brilliant extension first of all.

I'm working with project where all Models don't have Model suffix. Like described in the official documentation (https://book.cakephp.org/2/en/models.html#understanding-models)

So in case we have Component and Model with the same name it leads to Call to an undefined method BasicComponent::some_method.

Code sample:

<?php

class BasicComponent extends Component {}
<?php

class Basic extends Model
{
    public function some_method()
    {
    }
}
<?php

class FakeController extends Controller
{
    public $uses = [
        'Basic',
    ];

    public function add_smth()
    {
        $this->Basic->some_method();
    }
}

As I can see component service is setup first so probably it found BasicComponent and tries to look method inside of it only and doesn't take into account that models is also exists.

Ngôn ngữ chính
PHP
Star
2
Fork
3
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ariddlestone/phpstan-cakephp2

Tất cả issue của ariddlestone/phpstan-cakephp2

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.