Hướng dẫn php call function without $this - hàm gọi php mà không có $ this

Vì vậy, tôi có lớp học này:

class A{
      public function do_a[]{ return 'a_done';};

      public function do_b[]{ return 'b_done';};
}

Vì vậy, tôi yêu cầu tệp PHP và tạo một thể hiện của lớp:

require_once["A_class.php"];
$System = new A[];
require_once["user_calls.php"]; //here I import the user file with the function calls.

user_calls.php Nội dung:

echo 'this was the result of '.$System->do_a[];
echo 'this was the result of '.$System->do_b[];

Vì vậy, điều đó hoạt động, nhưng tôi không muốn người dùng phải sử dụng

require_once["A_class.php"];
$System = new A[];
require_once["user_calls.php"]; //here I import the user file with the function calls.
1, nhưng chỉ
require_once["A_class.php"];
$System = new A[];
require_once["user_calls.php"]; //here I import the user file with the function calls.
2.

Bất kỳ giải pháp?

Chỉnh sửa: Tôi cũng muốn giới hạn các chức năng mà người dùng có thể gọi trong tệp user_calls.php, đến các hàm php gốc cơ bản và các chức năng trong lớp A.

Đã hỏi ngày 13 tháng 1 năm 2012 lúc 16:00Jan 13, 2012 at 16:00

6

Tuyên bố miễn trừ trách nhiệm: Trong khi mã này hoạt động và thực hiện những gì bạn yêu cầu, điều đó không có nghĩa là tôi ủng hộ mã hóa như thế này. Rất khó để theo dõi các nhà phát triển khác [và thậm chí có thể bạn trong tương lai ...], và nó cũng sử dụng

require_once["A_class.php"];
$System = new A[];
require_once["user_calls.php"]; //here I import the user file with the function calls.
3, hầu như luôn luôn là một điều xấu [TM]. Điều đó nói rằng, bạn đi đây: While this code works, and does what you requested, that doesn't mean that I advocate coding like this. It's very hard to follow for other developers [and maybe even you in the future...], and it also makes use of
require_once["A_class.php"];
$System = new A[];
require_once["user_calls.php"]; //here I import the user file with the function calls.
3, which is almost always A Bad Thing[tm]. That said, here you go:

Bài Viết Liên Quan

Chủ Đề