V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yulanggong
V2EX  ›  PHP

PHP 在不知道变量名的情况下,有没有枚举所有变量的方法?

  •  
  •   yulanggong · Sep 6, 2012 · 4813 views
    This topic created in 4993 days ago, the information mentioned may be changed or developed.
    对 PHP 完全不熟,搜了半天也没找到相关的答案,不知道我这样描述是不是清楚。
    6 replies    1970-01-01 08:00:00 +08:00
    manhere
        1
    manhere  
       Sep 6, 2012   ❤️ 1
    get_defined_vars()
    shiny
        2
    shiny  
    PRO
       Sep 6, 2012   ❤️ 1
    get_defined_vars();

    除此之外还有系列的 get_defined_functions() 和 get_defined_constants()。
    手册读几遍就有印象了。
    yulanggong
        3
    yulanggong  
    OP
       Sep 6, 2012
    @manhere
    @shiny
    非常感谢,这个真的得看过才会有印象,我变换多次搜索词都没找到
    CupTools
        4
    CupTools  
       Sep 6, 2012   ❤️ 1
    还有一个很蛋疼的方法,var_dump($GLOBALS);
    hu437
        5
    hu437  
       Sep 6, 2012
    搜索关键词不正确吧,试试“PHP 反射”
    yulanggong
        6
    yulanggong  
    OP
       Sep 6, 2012
    @hu437 恩,的确是关键词不正确。我一开始用的关键词是 “php 枚举 变量”,后来发现“枚举”是个特殊的术语,用在这里并不合适,如果搜索“php 所有 变量”就能找到类似的答案了。而你说的“PHP 反射”是根本不可能预先知道的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5462 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 05:47 · PVG 13:47 · LAX 22:47 · JFK 01:47
    ♥ Do have faith in what you're doing.