我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

PHP命名空间和继承

I want to extend standard PDO class. So i have:

namespace Example;

class NewPDO extends PDO {}

but i get the following error :

Fatal error: Class 'Example\PDO' not found in /home/hdocs/lab/index.php on line 4

I know that's because PDO class is not within Example namespace.
how can i solve that ?

PDO is in global namespace, you should add \ before it.

namespace Example;

class NewPDO extends \PDO {}

近期文章

  • PHP数组检查现有索引
  • 如果Else语句语法错误[关闭]
  • 从数据库中读取php代码
  • 如何在数组中保留n个值?
  • 从Xpath查询中选择单个节点
  • 当php的mysql_query返回0时,会产生错误。 怎么修?
  • 在PHP中返回的替代方法?
  • 如何使表单提交按钮也重定向到页面中的特定div?
  • 将分隔的字符串数组分解为两个数组
  • json_encode()UTF-8错误
  • 隐藏URL中的ref字符串,但将其传递给脚本
  • PHP表单向MySQL数据库提交重复的条目
  • Pushing Boxes 推箱子的问题
  • 什么是序列化? [关闭]
  • 浮点数无法连接
  • 如何使用jQuery发布数据
  • Wordpress插件错误PHP
  • 删除密钥''警告的重复条目'''
  • 为什么这个变量回声为16?
  • 如何根据$ variable值触发查询?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华