子类父类不在同一个文件

pingheguo 2010-09-16 05:43:17
我的父类写在class.php中如下
<?php
class BaseClass {
function __construct() {
print "In BaseClass constructor\n"."<br>";
}
}

?>

继承类写在SubClass.php中
<?php
class SubClass extends BaseClass {
function __construct() {
parent::__construct();
print "In SubClass constructor\n";
}
}
$obj =new SubClass();
?>
在SubClass.php中
没有使用
include("class.php");是无法的执行的。

---------------------------------------

但是我见别人的源码都没有include("class.php");这句啊。
还有没有别的办法呢?
...全文
235 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
helloyou0 2010-09-16
  • 打赏
  • 举报
回复
还有autoload
neverfailor 2010-09-16
  • 打赏
  • 举报
回复
你可以用一些类似grep的软件
pingheguo 2010-09-16
  • 打赏
  • 举报
回复
对 的。。我想的不够。。不是这块料
CunningBoy 2010-09-16
  • 打赏
  • 举报
回复
这个类文件可以被其他的php文件include啊,这样在实际运行的php文件中子类和父类的文件都被include了。
pingheguo 2010-09-16
  • 打赏
  • 举报
回复
真的不懂 MallbaseApp这个父类怎么加载进来的
pingheguo 2010-09-16
  • 打赏
  • 举报
回复
ecmall 源码看过吗 我也不知道

这个是一个类的文件。



<?php

/* 申请开店 */
class ApplyApp extends MallbaseApp
{

function index()
{
/* 判断是否开启了店铺申请 */
if (!Conf::get('store_allow'))
{
$this->show_warning('apply_disabled');
return;
}

/* 只有登录的用户才可申请 */
if (!$this->visitor->has_login)
{
$this->login();
return;
}

/* 已申请过或已有店铺不能再申请 */
$store_mod =& m('store');
$store = $store_mod->get_info($this->visitor->get('user_id'));
if ($store)
{
if ($store['state'])
{
$this->show_warning('user_has_store');
return;
}
else
{
$this->show_warning('user_has_application');
return;
}
}
$sgrade_mod =& m('sgrade');
$step = isset($_GET['step']) ? intval($_GET['step']) : 1;
switch ($step)
{
case 1:
$sgrades = $sgrade_mod->find(array(
'order' => 'sort_order',
));
foreach ($sgrades as $key => $sgrade)
{
if (!$sgrade['goods_limit'])
{
$sgrades[$key]['goods_limit'] = LANG::get('no_limit');
}
if (!$sgrade['space_limit'])
{
$sgrades[$key]['space_limit'] = LANG::get('no_limit');
}
$arr = explode(',', $sgrade['functions']);
$subdomain = array();
foreach ( $arr as $val)
{
if (!empty($val))
{
$subdomain[$val] = 1;
}
}
$sgrades[$key]['functions'] = $subdomain;
unset($arr);
unset($subdomain);
}
$this->assign('domain', ENABLED_SUBDOMAIN);
$this->assign('sgrades', $sgrades);

$this->assign('page_title', Lang::get('title_step1') . ' - ' . Conf::get('site_title'));
$this->display('apply.step1.html');
break;
case 2:
$sgrade_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$sgrade = $sgrade_mod->get($sgrade_id);
if (empty($sgrade))
{
$this->show_message('request_error',
'back_step1', 'index.php?app=apply');
exit;
}

if (!IS_POST)
{
$region_mod =& m('region');
$this->assign('site_url', site_url());
$this->assign('regions', $region_mod->get_options(0));
$this->assign('scategories', $this->_get_scategory_options());

/* 导入jQuery的表单验证插件 */
$this->import_resource(array('script' => 'mlselection.js,jquery.plugins/jquery.validate.js'));

$this->assign('page_title', Lang::get('title_step2') . ' - ' . Conf::get('site_title'));
$this->display('apply.step2.html');
}
else
{
$store_mod =& m('store');

$store_id = $this->visitor->get('user_id');
$data = array(
'store_id' => $store_id,
'store_name' => $_POST['store_name'],
'owner_name' => $_POST['owner_name'],
'owner_card' => $_POST['owner_card'],
'region_id' => $_POST['region_id'],
'region_name' => $_POST['region_name'],
'address' => $_POST['address'],
'zipcode' => $_POST['zipcode'],
'tel' => $_POST['tel'],
'sgrade' => $sgrade['grade_id'],
//'apply_remark' => $_POST['apply_remark'],
'state' => $sgrade['need_confirm'] ? 0 : 1,
'add_time' => gmtime(),
);
$image = $this->_upload_image($store_id);
if ($this->has_error())
{
$this->show_warning($this->get_error());

return;
}
if ($store_mod->add(array_merge($data, $image)) === false)
{
$this->show_warning($store_mod->get_error());
return;
}

$cate_id = intval($_POST['cate_id']);
if ($cate_id > 0)
{
$store_mod->createRelation('has_scategory', $store_id, $cate_id);
}

if ($sgrade['need_confirm'])
{
$this->show_message('apply_ok',
'index', 'index.php');
}
else
{
$this->send_feed('store_created', array(
'user_id' => $this->visitor->get('user_id'),
'user_name' => $this->visitor->get('user_name'),
'store_url' => SITE_URL . '/' . url('app=store&id=' . $store_id),
'seller_name' => $data['store_name'],
));
$this->_hook('after_opening', array('user_id' => $store_id));
$this->show_message('store_opened',
'index', 'index.php');
}
}
break;
default:
header("Location:index.php?app=apply&step=1");
break;
}
}

function check_name()
{
$store_name = empty($_GET['store_name']) ? '' : trim($_GET['store_name']);

$store_mod =& m('store');
if (!$store_mod->unique($store_name))
{
echo ecm_json_encode(false);
return;
}
echo ecm_json_encode(true);
}

/* 上传图片 */
function _upload_image($store_id)
{
import('uploader.lib');
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
$uploader->allowed_size(SIZE_STORE_CERT); // 400KB

$data = array();
for ($i = 1; $i <= 3; $i++)
{
$file = $_FILES['image_' . $i];
if ($file['error'] == UPLOAD_ERR_OK)
{
if (empty($file))
{
continue;
}
$uploader->addFile($file);
if (!$uploader->file_info())
{
$this->_error($uploader->get_error());
return false;
}

$uploader->root_dir(ROOT_PATH);
$dirname = 'data/files/mall/application';
$filename = 'store_' . $store_id . '_' . $i;
$data['image_' . $i] = $uploader->save($dirname, $filename);
}
}
return $data;
}

/* 取得店铺分类 */
function _get_scategory_options()
{
$mod =& m('scategory');
$scategories = $mod->get_list();
import('tree.lib');
$tree = new Tree();
$tree->setTree($scategories, 'cate_id', 'parent_id', 'cate_name');
return $tree->getOptions();
}
}

?>



CunningBoy 2010-09-16
  • 打赏
  • 举报
回复
不可能的,一定在你没有注意地方加了include或者require
pingheguo 2010-09-16
  • 打赏
  • 举报
回复
include
require
都是加载的意思把

有没有别的办法使这些文件关联呢

不要每个文件都要
include
require
我是菜鸟
pingheguo 2010-09-16
  • 打赏
  • 举报
回复
但是别人什么都有。。
heyli 2010-09-16
  • 打赏
  • 举报
回复
不用include 用require()
CunningBoy 2010-09-16
  • 打赏
  • 举报
回复
require也可以

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧