标签: scopes

Call to undefined function with PHP

I have this class:

class testclass{
    function func1(){
        return "hello";
    }
    function func2(){
        echo func1();
    }
}
Run Code Online (Sandbox Code Playgroud)

When I am running

$test = new testclass();
$test->func2();
Run Code Online (Sandbox Code Playgroud)

I get an error: Fatal error: Call to undefined function func1() with the line index of echo func1();

My question now is, how do I make the func2 recognize func1

Is this a problem with the scopes?

php function undefined scopes

0
推荐指数
1
解决办法
372
查看次数

C++ 11-作用域和全局变量

如何从内部作用域访问全局变量,给定以下代码示例,如何从主函数和最内部作用域访问全局字符串 X,一旦我们退出它,最内部作用域也是可访问的主要范围还是其他范围?

#include <iostream>
#include <string>
std::string x = "global";
int counter = 1;

int main()
{
    std::cout <<counter ++ << " " << x << std::endl;
    std::string x = "main scope";
    std::cout <<counter ++ << " "  << x << std::endl;
    {
        std::cout <<counter ++ << " " << x << std::endl;
        std::string x = "inner scope";
        std::cout <<counter ++ << " " << x << std::endl;
    }
    std::cout <<counter++ << " "  << x << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

目前的 …

scopes c++11

0
推荐指数
1
解决办法
652
查看次数

@SessionScoped是一个好习惯吗?

我已经阅读了范围(@SessionScoped, @ViewScoped, @ApplicationScope and @RequestScope)类型之间的所有差异,但是,我仍然在某种程度上遇到应用程序问题。我有一个page-1 与网格和我所选择的项目发送到page-2(两者page-1page-2用相同的支持bean),以进行编辑,然后持续存在。据我所知,我的托管bean正在使用@RequestScopedjavax.faces.bean.RequestScoped这是理想的使用范围,但是它不起作用,bean被破坏了,数据丢失了。

恢复该故事,我将注释更改为@SessionScoped并且可以正常工作,但是我想知道这是否是一个好习惯?因为我已经读到,使用这种方法不是一个好习惯,@SessionScoped因为在客户端注销之前数据将一直保持活动状态。

jsf session-scope scopes

0
推荐指数
1
解决办法
6614
查看次数

Google OAuth 同意屏幕不显示新请求的敏感范围

我已请求 Google 批准敏感范围。到目前为止,该应用程序正在访问基本的姓名和电子邮件数据。但是,新请求的范围不会显示在同意屏幕上。Google 要求我与新的 OAuth 同意屏幕共享视频,但在他们更新之前我无法显示新范围。我究竟做错了什么?我查找了其他问题和资源,但没有找到与敏感范围相关的特定于此问题的任何问题。在此输入图像描述

在此输入图像描述 在此输入图像描述

screen oauth scopes

0
推荐指数
1
解决办法
1486
查看次数

python 文字是否保存在函数体内?

我有一个函数需要在一个相当紧密的循环中执行,所以它对性能很敏感。它的过滤功能旨在节省更昂贵的工作。大多数功能只是对静态列表的检查。

所以(去掉一些不相关的细节)我可以在这里做两件不同的事情:

 def my_filter(arg):
    SAFE_VALS = {
        'a',
        'b',
        'f',
        'i',
        'm'
    }
   # the real list is much larger, but 
   # it is a static set like the above...

    return arg in SAFE_VALS
Run Code Online (Sandbox Code Playgroud)

或者

 # make this a module level constant
 SAFE_VALS = {
        'a',
        'b',
        'f',
        'i',
        'm'
    }

 def my_filter(arg):
    return arg in SAFE_VALS
Run Code Online (Sandbox Code Playgroud)

我知道 Python 将不得不查看更高的范围级别才能找到模块级别的版本——但我不知道的是,my_filter每次运行函数时,编译版本是否有效地重新创建了这个集合,或者文字是否“烘焙” in" 到函数 def. 如果每次调用都分配一个新集合,那么我感觉使用模块级版本会更好——如果不是,我不会通过将文字提升到函数范围之外而获得任何好处。

现在分析数据足够嘈杂,我没有看到明显的区别。但是,如果该集合包含更多的长字符串,我会吗?或者,这些形式之间是否存在显着差异?

python scopes

-1
推荐指数
1
解决办法
32
查看次数

标签 统计

scopes ×5

c++11 ×1

function ×1

jsf ×1

oauth ×1

php ×1

python ×1

screen ×1

session-scope ×1

undefined ×1