GVKun编程网logo

无法重新声明函数php(无法重新声明块范围变量)

31

本文将带您了解关于无法重新声明函数php的新内容,同时我们还将为您解释无法重新声明块范围变量的相关知识,另外,我们还将为您提供关于c–为什么我必须从继承的类重新声明虚函数?、c–重新声明时替换函数默认

本文将带您了解关于无法重新声明函数php的新内容,同时我们还将为您解释无法重新声明块范围变量的相关知识,另外,我们还将为您提供关于c – 为什么我必须从继承的类重新声明虚函数?、c – 重新声明时替换函数默认参数、C:函数是否重新声明了一个未定义的行为?、Discuz 3x 重新声明内置函数 $ 解决 jQuery 冲突的实用信息。

本文目录一览:

无法重新声明函数php(无法重新声明块范围变量)

无法重新声明函数php(无法重新声明块范围变量)

参见英文答案 > “Fatal error: Cannot redeclare <function>”                                    14个
我有一个名为parseDate的函数,但当我在我的PHP页面上调用它时(它是一个joomla组件页面)我得到致命错误:无法重新声明parsedate()(之前在templates / ja_zeolite / assets / functions.PHP:2中声明)in第21行的templates / ja_zeolite / assets / functions.PHP

第2行是函数解析($data),第21行是}(函数结束).
功能是:

function parseDate($date){
$items = explode('.',$date);
switch($items[1]){
    case 1: $mese = 'Gen'; break;
    case 2: $mese = 'Feb'; break;
    case 3: $mese = 'Mar'; break;
    case 4: $mese = 'Apr'; break;
    case 5: $mese = 'Mag'; break;
    case 6: $mese = 'Giu'; break;
    case 7: $mese = 'Lug'; break;
    case 8: $mese = 'Ago'; break;
    case 9: $mese = 'Set'; break;
    case 10: $mese = 'ott'; break;
    case 11: $mese = 'Nov'; break;
    case 12: $mese = 'Dic'; break;
    default: $mese = '---';
}
$data_corretta = array(0 => $mese,1 => $items[2]);
return $data_corretta;
}

我也尝试更改名称功能,但它仍然无效.

为什么?

解决方法

您(或Joomla)可能会多次包含此文件.将您的函数包含在条件块中:

if (!function_exists('parseDate')) {
    // ... proceed to declare your function
}

c – 为什么我必须从继承的类重新声明虚函数?

c – 为什么我必须从继承的类重新声明虚函数?

我正在研究一个简单的C程序,并且很难理解我遇到的编译器错误.这个问题是由我尝试从基类创建派生类引起的.我在下面发布了相同结构的代码,但更改了名称.

BaseClass.h

#ifndef BASECLASS_H#define BASECLASS_Hclass BaseClass {    public:        BaseClass(void);        virtual int method1(void) = 0;        virtual int method2(void) = 0;        virtual float method3(void) = 0;};#endif // BASECLASS_H

DerivedClass.h

#ifndef DERIVEDCLASS_H#define DERIVEDCLASS_H#include "DerivedClass.h"class DerivedClass: public BaseClass{    public:        DerivedClass(void);     };#endif // DERIVEDCLASS_H

DerivedClass.cpp

#include "DerivedClass.h"DerivedClass::DerivedClass(void){}int DerivedClass::method1(void){  // Todo} int DerivedClass::method2(void){  // Todo}float DerivedClass::method3(void) {  // Todo}

尝试编译时,我得到所有虚拟方法的以下错误:

no 'int DerivedClass::methodX()' member function declared in class 'DerivedClass'

一旦我在’DerivedClass.h’中声明这些方法,错误就会消失,因为编译器现在知道这些方法.

但是,我很困惑.为什么有必要在DerivedClass.h中重新声明纯虚函数?当我#include DerivedClass.h时,它将自动包含BaseClass.h,因此我假设我的DerivedClass.cpp应该完全了解这些方法.我做错了吗?

解决方法

它没有这种方式.您需要声明要定义的方法,无论它们是否覆盖虚拟方法.

这不仅仅是语言的无理要求.如果没有这个,您将无法定义部分虚拟类,即,您可以使BaseSubtype具有method1()的通用实现,但需要从其派生的类来实现method2()和method3()

c – 重新声明时替换函数默认参数

c – 重新声明时替换函数默认参数

参见英文答案 > Default argument in the middle of parameter list?                                    2个
为什么以下代码格式正确:

void foo(int i,int j = 56);
void foo(int i = 42,int j);

int main(){  }

DEMO

但以下

void foo(int i = 42,int j);
void foo(int i,int j = 56);

int main(){  }

DEMO

是不正确的.我试着查看N4296 :: 8.3.6 [dcl.fct.default],我发现的是以下示例:

class C 
{
    void f(int i = 3);
    void g(int i,int j = 99);
};
void C::f(int i = 3) { } //error
void C::g(int i = 88,int j) { // C::g can be called with no argument
}

但是clang似乎并不那样.

struct A
{
    void foo(int i = 42,int j);
};

void A::foo(int i,int j = 56){ }; //error

int main(){  }

DEMO

那么,这是一个实施问题吗?在形式上,所有这个例子应该是可以接受的,如果它们?

解决方法

[dcl.fct.default]

  1. […]default arguments can be added in later declarations of a function in the same scope.
void foo(int i,int j);

这很好,因为第二个声明是为第一个参数添加一个默认参数,该参数之前没有.

[…]In a given function declaration,each parameter subsequent to a parameter with a default argument shall have a default argument supplied in this or a prevIoUs declaration[…]

第二个声明中的第二个参数已经有一个默认参数,尝试提供另一个参数将是一个错误.

void foo(int i = 42,int j); // error
void foo(int i,int j = 56);

这是一个错误,因为第一个声明为第一个参数提供了默认参数,但没有为第二个参数提供默认参数,并且与第一个示例不同,之前没有声明.

struct A
{
    void foo(int i = 42,int j); // the error should be here
};

void A::foo(int i,int j = 56){ }; // not here

这与上面完全相同的原因是不正确的,j在初始声明中没有默认参数,示例中的下一行是无关紧要的.

C:函数是否重新声明了一个未定义的行为?

C:函数是否重新声明了一个未定义的行为?

码:
#include <iostream>
using namespace std;

int f(int x = 0) {
    cout << "x:" << x << endl;
    return 0;
}
int main() {
    f();
    int f(int x = 1);
    f();
    return 0;
}

Output(在g 5.1上测试):

x:0
x:1

我的问题:

>是int f(int x = 1);声明或定义?
>函数重新声明是否像未定义的行为?

解决方法

从 dcl.fct.default的§8.3.6开始:
  1. For non-template functions,default arguments can be added in later declarations of a function in the
    same scope. Declarations in different scopes have completely distinct sets of default arguments.

没有未定义的行为.你所看到的是强制性的.

Discuz 3x 重新声明内置函数 $ 解决 jQuery 冲突

Discuz 3x 重新声明内置函数 $ 解决 jQuery 冲突

Discuz x3 自带的 JS 使用 $ 做内置函数,这样就和 JQ 冲突了,导致原来的功能也不能用了,东子找过别人修改了一份 JQ 不冲突的,后来发现在引用的 JQ 后面加上一句话,重新声明内置函数 $ 赋一个值,也能解决冲突,这样不是更方便呢。

先引用 JQ 文件,然后后面加上这句话,内置函数名可以自己定义

<script language="javascript" > var G = jQuery.noConflict();</script>

比如我改成了 G ,以前这样写的 $("body") 就成了 G("body")

声明:本文采用 BY-NC-SA 协议进行授权,转载还请注明:Discuz 3x 重新声明内置函数 $ 解决 jQuery 冲突

关于无法重新声明函数php无法重新声明块范围变量的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于c – 为什么我必须从继承的类重新声明虚函数?、c – 重新声明时替换函数默认参数、C:函数是否重新声明了一个未定义的行为?、Discuz 3x 重新声明内置函数 $ 解决 jQuery 冲突的相关信息,请在本站寻找。

本文标签: