我有一个包括类的问题.这是一个解释问题的简单示例:
班级号 1(路径:/home/day/Class_A.php):
class Class_A {
public function sayHi() {
echo "Good day";
}
}
Run Code Online (Sandbox Code Playgroud)
班级号 2(路径:/home/test/Class_B.php):
class Class_B {
public function greeting() {
if(class_exists("Class_A")!=true)
include "../day/Class_A.php";
$test = new Class_A();
$test->sayHi();
}
}
Run Code Online (Sandbox Code Playgroud)
PHP文件(路径:/home/php.php)
if(class_exists("Class_B")!=true)
include "test/Class_B.php";
$g = new Class_B;
$g->greeting();
Run Code Online (Sandbox Code Playgroud)
问题是当php.php包含Class_B且Class_B包含Class_A时,Class_B无法打开Class_B,因为类的对象的路径现在与php.php文件相同.
我的问题是:有没有一种简单的方法来解决这个问题?
有没有办法在javascript中包含一些php文件onClick?
喜欢,
if(isset(something)) ?
include "file.php";
Run Code Online (Sandbox Code Playgroud)
请帮忙!
例如:
file1.c 具有:
static const struct
{
int a;
int b;
int c;
} mystruct = { 1, 2, 3};
Run Code Online (Sandbox Code Playgroud)
file2.c 具有:
#include <stdio.h>
#include "file1.c"
Run Code Online (Sandbox Code Playgroud)
等等.
这样可以吗?
我遇到了以下我无法解决的错误.
1>k:\school\c++\project_2\project_2\mechanic.h(8): fatal error C1014: too many include files : depth = 1024
1> Maintenance.cpp
1>k:\school\c++\project_2\project_2\maintenance.h(8): fatal error C1014: too many include files : depth = 1024
(continues for many other files in the project)...
Run Code Online (Sandbox Code Playgroud)
项目的示例头文件:bicycle.h
//#pragma once //Make sure it's included only once
using namespace std;
#include <iostream>
#include "Date.h"
#include "Cyclist.h"
#include "Maintenance.h"
#ifndef BICYCLE_H_
#define BICYCLE_H_
class Bicycle
{
public:
Bicycle(Date, int, int, Cyclist);
~Bicycle(void);
Datum getDateJoined() const;
int getFrameSize() const;
int getBicycleID() const;
Cyclist getCyclist();
void …Run Code Online (Sandbox Code Playgroud) 此代码曾用于早期版本的PHP4,但由于托管服务器已升级到PHP5,因此不再适用于我的网站.有没有简单的方法来改变这段代码,让它再次运作?
<?
if ($info == "file1") {include ("file1.html");}
if ($info == "file2") {include ("file2.html");}
if ($info == "file3") {include ("file3.html");}
if ($info == "file4") {include ("file4.html");}
if ($info == "file5") {include ("file5.html");}
?>
Run Code Online (Sandbox Code Playgroud)
编辑:是的,这是我在最终网站上的代码(这里不是PHP专业版).我只是在一个简单的链接中调用"$ info = _ "(我想返回www.website.com/?info=file),即:
<a href="?info=file1">Click here to read File 1</a>
Run Code Online (Sandbox Code Playgroud) 好的,所以我是一名HTML/Javascript/PHP专业人士,但我正在努力学习C++.我还是新手,我有一个C++编程项目,我有错误.
包含int main()的文件是'football.cpp',我有三个必须使用的类的.h和.cpp文件:Game,Team和Date.Team的每个实例都包含一个Games游戏,每个游戏都包含一个Date.日期不包含任何其他类的实例.
我试图找到一种方法在文件的顶部使用#include和#ifndef语句,这样我编译时就不会出错,但我还没有找到一个有效的组合.我不确定是否还有其他错误.这是我目前的#include部分,不包括其他库:
football.cpp
#include "game.h"
#include "team.h"
#include "date.h"
Run Code Online (Sandbox Code Playgroud)
team.h
#ifndef __game_h_
#define __game_h_
#endif
Run Code Online (Sandbox Code Playgroud)
team.cpp
#include "team.h"
#ifndef __game_h_
#define __game_h_
#endif
Run Code Online (Sandbox Code Playgroud)
game.h
#ifndef __date_h_
#define __date_h_
#endif
Run Code Online (Sandbox Code Playgroud)
game.cpp
#include "game.h"
#ifndef __date_h_
#define __date_h_
#endif
Run Code Online (Sandbox Code Playgroud)
date.cpp
#include "date.h"
Run Code Online (Sandbox Code Playgroud)
我使用Cygwin g ++编译器,我用来编译它的行是:
g++ football.cpp team.cpp game.cpp date.cpp -o football.exe
Run Code Online (Sandbox Code Playgroud)
以下是我得到的所有错误:(警告,文字墙)
$ g++ football.cpp team.cpp game.cpp date.cpp -o football.exe
In file included from football.cpp:9:0:
game.h:15:96: error: ‘Date’ has not been declared
game.h:24:1: error: ‘Date’ does not name a …Run Code Online (Sandbox Code Playgroud) 我有3个类:A,B和C.C #include由B编辑,B #includ由A编辑.在C类中,我为按钮定义了一个处理程序,当按下按钮时,C将PostMessage对象A.我在C中包含A,我将有一个循环引用,那么我该怎么做才能避免这种循环引用?
编辑:所有包含都是在实现文件中.
基本上,我想这样做:
<script src=" path + '/jquery.js'"></script>
Run Code Online (Sandbox Code Playgroud)
(显然这不起作用.)
我有一个独立页面加载外部脚本<script>,但URL需要以变量为前缀path(因为页面在不同环境中的不同服务器上运行).我很容易path从URL中找到"?path = X ",其中X是实际路径.
如果我有jQuery,我知道我可以getScript()用来动态加载外部.js文件,但jQuery是我需要加载的文件之一!我不需要在这里过于复杂,不需要担心编码或文件类型,除了更改服务器之外,这是一个相当简单的情况.
我需要将file_1.c包含到main.c中.在file_1.c中,我目前有多个功能.如果我想在main.c中调用这些函数,我需要做什么?我的主程序中有#include"file_1.c".
我正在尝试在页面中包含一个文件.该文件位于名为phpThumb的文件夹中,该文件夹位于我的wordpress主题目录中.
这就是我试图包含文件的方式"
<?php require_once(get_bloginfo('template_url')."/phpThumb/phpThumb.config.php"); ?>
出于某种原因,这不起作用.
我检查并get_bloginfo() 返回一个值,但不回显值.
我三重检查了代码的有效性,这一切都很好IMO ...
什么可能是错的?
PS; 它工作正常,$_SERVER['DOCUMENT_ROOT']但它的输出依赖于当前页面(如果我错了,请纠正我)所以它对我来说效率不高.