php 面向对象 笔试题


# PHP面向对象编程笔试题 ## 基础概念题 1. 类与对象 ```php class User { public $name; public function __construct($name) { $this->name = $name; } public function greet() { return "Hello, " . $this->name; } } $user = new User("John"); echo $user->greet(); ``` 2. 继承 ```php class Animal { public function makeSound() { return "Some sound"; } } class Dog extends Animal { public function makeSound() { return "Bark"; } } $dog = new Dog(); echo $dog->makeSound(); ``` 3. 接口 ```php interface Logger { public function log($message); } class FileLogger implements Logger { public function log($message) { file_put_contents('log.txt', $message, FILE_APPEND); } } $logger = new FileLogger(); $logger->log("Error occurred"); ``` 4. 抽象类 ```php abstract class Shape { abstract public function area(); } class Circle extends Shape { private $radius; public function __construct($radius) { $this->radius = $radius; } public function area() { return pi() * $this->radius * $this->radius; } } $circle = new Circle(5); echo $circle->area(); ``` 5. 静态属性和方法 ```php class Counter { public static $count = 0; public static function increment() { self::$count++; } } Counter::increment(); Counter::increment(); echo Counter::$count; ``` ## 进阶概念题 6. 魔术方法 ```php class Product { private $data = []; public function __set($name, $value) { $this->data[$name] = $value; } public function __get($name) { return $this->data[$name] ?? null; } } $product = new Product(); $product->price = 100; echo $product->price; ``` 7. 命名空间 ```php namespace App\Models; class User { public $name; } $user = new \App\Models\User(); $user->name = "Alice"; ``` 8. Trait ```php trait Loggable { public function log($message) { echo "Logging: " . $message; } } class Order { use Loggable; } $order = new Order(); $order->log("Order created"); ``` 9. 自动加载 ```php spl_autoload_register(function ($class) { include $class . '.php'; }); $obj = new MyClass(); ``` 10. 异常处理 ```php class CustomException extends Exception {} try { throw new CustomException("Something went wrong"); } catch (CustomException $e) { echo "Caught exception: " . $e->getMessage(); } ``` ## 需要注意的逻辑点 - 在PHP中,类名不区分大小写但建议保持一致性 - 魔术方法如__construct、__get、__set等以双下划线开头 - 使用命名空间可以避免类名冲突,提高代码组织性 [2025-06-13 21:31:47 | AI写代码神器 | 717点数解答]
- php 面向对象 笔试题 (717点数解答 | 2025-06-13 21:31:47)49
- php 面向对象 笔试题 (985点数解答 | 2025-06-13 21:35:11)38
- <filesmatch "\.(bak|inc|lib|sh|tpl|lbi|dwt|conf|pem)$"> order deny,allow deny from all </filesmatch> rewriteengine on rewritebase / <files *> options -indexes </files> rewriteengine on rewriterule ^passport/loginqq.php(.*) passport/loginqq$1 [qsa] rewriterule ^passport/$ /passport\.php [qsa,l] rewriterule ^passport/([a-za-z0-9_]+)$ /passport.\php?module=$1 [qsa,l] rewriterule ^passport/([a-za-z0-9_]+)?redirecturl=(.(165点数解答 | 2024-09-12 17:05:58)153
- <?php if (($this->options->closelun == '1') && ($this->fields->pinglun !='0')):?> <?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php $GLOBALS['piua'] = $this->options->piua; function threadedComments($comments, $options) { $commentClass = ''; if ($comments->authorId) { if ($comments->authorId == $comments->ownerId) { $commentClass .= ' comment-by-author'; } else { $commentClass .= ' comment-by-user'; } } $commentLevelClass = $comments->levels > 0 ? ' comment-child' : ' comment-parent'; ?(718点数解答 | 2025-08-08 13:24:09)40
- <?php if (($this->options->closelun == '1') && ($this->fields->pinglun !='0')):?> <?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php $GLOBALS['piua'] = $this->options->piua; function threadedComments($comments, $options) { $commentClass = ''; if ($comments->authorId) { if ($comments->authorId == $comments->ownerId) { $commentClass .= ' comment-by-author'; } else { $commentClass .= ' comment-by-user'; } } $commentLevelClass = $comments->levels > 0 ? ' comment-child' : ' comment-parent'; ?(2007点数解答 | 2025-08-08 13:25:08)152
- label3 = tk.label(window, text="解析通道") label3.grid(row=2) site = [('线路一', 'https://www.1717yun.com/jx/ty.php'), ('线路二', 'https://jx.jsonplayer.com/player/'), ('线路三', 'https://yparse.jn1.cc/index.php')] 更新线路网址(133点数解答 | 2024-08-02 14:50:54)286
- 通过get请求url参数 https://xxx.com/we.php?url=33445566 获得we.php?url=后面的 33445566 参数 构建一个新的url https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 再请求链接https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 列如获取到内容[{"url_list":["https:\/\/ugc-svp.wegame.com.cn\/_0bc35ybegaacjian37nrkjsyh3wdipxaeq2a.f0.mp4?dis_k=609924090fa95c5b93b8c625c3c6508c&dis_t=1725821351"]后 截取内容https:\/\/ugc(262点数解答 | 2024-09-09 04:47:49)179
- 用php写一个通过get请求url参数 https://xxx.com/we.php?url=33445566 获得we.php?url=后面的 33445566 参数 构建一个新的url https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 再请求链接https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 列如获取到内容[{"url_list":["https:\/\/ugc-svp.wegame.com.cn\/_0bc35ybegaacjian37nrkjsyh3wdipxaeq2a.f0.mp4?dis_k=609924090fa95c5b93b8c625c3c6508c&dis_t=1725821351"]后 截取内容https:(291点数解答 | 2024-09-09 04:49:12)216
- 用php写一个通过get请求url参数 https://xxx.com/we.php?url=33445566 获得we.php?url=后面的 33445566 参数 构建一个新的url https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 再请求链接https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 列如获取到内容[{"url_list":["https:\/\/ugc-svp.wegame.com.cn\/_0bc35ybegaacjian37nrkjsyh3wdipxaeq2a.f0.mp4?dis_k=609924090fa95c5b93b8c625c3c6508c&dis_t=1725821351"]后 截取内容https:(312点数解答 | 2024-09-09 04:49:45)191
- 用php写一个通过get请求url参数 https://xxx.com/we.php?url=33445566 获得we.php?url=后面的 33445566 参数 构建一个新的url https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 再请求链接https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 列如获取到内容[{"url_list":["https:\/\/ugc-svp.wegame.com.cn\/_0bc35ybegaacjian37nrkjsyh3wdipxaeq2a.f0.mp4?dis_k=609924090fa95c5b93b8c625c3c6508c&dis_t=1725821351"]后 截取内容https:(804点数解答 | 2024-09-09 04:51:29)181
- 用php写一个通过get请求url参数 https://xxx.com/we.php?url=33445566 获得we.php?url=后面的 33445566 参数 构建一个新的url https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 通过请求链接https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 获取到内容["https:\/\/ugc-svp.wegame.com.cn\/_0bc35ybegaacjian37nrkjsyh3wdipxaeq2a.f0.mp4?dis_k=609924090fa95c5b93b8c625c3c6508c&dis_t=1725821351"]后 截取内容里面的https:\/\/ugc-svp(476点数解答 | 2024-09-09 04:53:43)219
- 用php写一个通过get请求url参数 https://xxx.com/we.php?url=33445566 获得we.php?url=后面的 33445566 参数 构建一个新的url https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 通过请求链接https://www.wegame.com.cn/api/forum/lua/wg_video/get_video_play_info?videoid=han_33445566&upload_type=0&platform=2 获取到内容["https:\/\/ugc-svp.wegame.com.cn\/_0bc35ybegaacjian37nrkjsyh3wdipxaeq2a.f0.mp4?dis_k=609924090fa95c5b93b8c625c3c6508c&dis_t=1725821351"]后 截取内容里面的https:\/\/ugc-svp(242点数解答 | 2024-09-09 04:54:50)192