包含具有相同变量名称的文件

时间:2015-06-30 19:42:51

标签: php

a.php只会

let y_align = 340 * index + 70
let x_align = self.deviceWidth - 110
var derp = UILabel(frame: CGRectMake(0, 0, 200, 21))
derp.center = CGPointMake(CGFloat(x_align), CGFloat(y_align))    
derp.textAlignment = NSTextAlignment.Right    
derp.text = json["things"][index]["thing"].string!    
self.some_view_container.addSubview(derp)

//now this is what I understand about constraints    
let xconstraint = NSLayoutConstraint(    
    item: derp, //-- the object that we want to constrain    
    attribute: NSLayoutAttribute.Trailing, //-- the attribute of the object we want to constrain    
    relatedBy: NSLayoutRelation.Equal, //-- how we want to relate THIS object to A DIFF object    
    toItem: some_view_container, //-- this is the different object we want to constrain to    
    attribute: NSLayoutAttribute.Right, //-- the attribute of the different object    
    multiplier: 1, //-- multiplier    
    constant: 8 //-- regular constant    
)

derp.addConstraint(xconstraint)

B.php

define("_a_","hey!");

的index.php

define("_a_","wow!");

调用getFile

function getFile($type) {
  include_once($type . ".php");
  echo _a_;
}

然后我交换了调用函数的顺序

getFile(A); //--> Output "hey!"
getFile(B); //--> Output "hey!" HERE IS THE PROBLEM, SHOULD ECHO "wow!"

感谢所有帮助

1 个答案:

答案 0 :(得分:7)

来自PHP official documentation

bool define ( string $name , mixed $value [, bool $case_insensitive = false ] )  
  

在运行时定义命名的 CONSTANT

因此,如果它定义了不可更改的值,则意味着您无法在运行时更改该值。

修改: 您可以使用变量从包含的文件中获取数据。当您包含脚本时,您基本上是使用copy& amp;创建新脚本。粘贴来自包含文件的内容并执行该新脚本。 Passing a variable from other script - PHP