English 中文(简体)
如何“全球化”购买力平价变量?
原标题:How to "globalize" PHP variables?

我有一个名为“变革ApprovalInfo.php”的网页。 其职能如下:

function Row_Rendered() {

    // To view properties of field class, use:
    //var_dump($this-><FieldName>);

    $RecordOwner = $this->RequestUser->CurrentValue;  
        echo $RecordOwner;
} 

账单 所有人拿到我的数据,我需要在另一页进行q问。

我有另一页称为“变革ApprovalEdit.php—— 页: 1

<?php include_once "ChangeApprovalinfo.php" ?>

档案顶部。

改变ApprovalEdit.php的功能是,我需要变换ApprovalInfo所界定的“Record Ownerr”变量。

如果在《改革法》上加上“债务”一词。 我看到了一个错误,说它是一个不为人知的变数。 我的理解是,我需要“使它成为全球性的”或某种此类业务。 我对购买力平价了解甚少,我正在编辑的网页很长而且很复杂。 (至少对我而言)

  • What do I need to do? I know that the information I have provided might not be enough to answer the question. I don t know enough to even know exactly what I need to ask. If more information is needed, I will edit and follow up.

档案的过去

ChangeApprovalInfo.php = http://pastebin.com/bSRM1wwN
ChangeApprovalEdit.php = http://pastebin.com/AStG9pqb

EDIT: Changing Row_Rendered to this seems to be more effective. I m having trouble seeing WHERE I can later echo this variable... but I m getting somewhere with this...

function Row_Rendered() {
    // To view properties of field class, use:
    //var_dump($this-><FieldName>);
    $GLOBALS[ RecordOwner ] = $this->RequestUser->CurrentValue;  
} 
问题回答

Don t echo variables from functions, which just outputs them to the standard output. return them from the function so you can 用途the value elsewhere as well.

function Row_Rendered() {
    $RecordOwner = $this->RequestUser->CurrentValue;  
    return $RecordOwner;
} 

之后改为

$obj->Row_Rendered();

用途

echo $obj->Row_Rendered();

and if you want to 用途the value elsewhere, 用途

$value = $obj->Row_Rendered();

You can do a couple of things:

首先,您可从该职能中收回<代码>$Record Ownerr,并将其价值储存在一个变量中。 这种方法通常更可取。

function Row_Rendered() {

    // To view properties of field class, use:
    //var_dump($this-><FieldName>);

    $RecordOwner = $this->RequestUser->CurrentValue;  
        echo $RecordOwner;

    return $RecordOwner;
} 

// Store it in a variable when calling the function.
$RecordOwner = Row_Rendered();

或者,你可以使其在全球职能范围内:

function Row_Rendered() {

    // To view properties of field class, use:
    //var_dump($this-><FieldName>);

    $GLOBALS[ RecordOwner ] = $this->RequestUser->CurrentValue;  
        echo $GLOBALS[ RecordOwner ];
} 

您可使用$GLOBALS超全球s阵列,如:

function Row_Rendered() {
  $GLOBALS[ RecordOwner ] = $this->RequestUser->CurrentValue;  
}

但是,should not do that。 相反,对你的申请加以修改,以便把意见列入<代码> ChangeApprovalinfo.php 仅包含一项职能,然后用适当的参数加以规定。

EDIT: Chaning Row_Rendered to this seems to be more effective. I m having trouble seeing WHERE I can later echo this variable... but I m getting somewhere with this...

function Row_Rendered() {
    // To view properties of field class, use:
    //var_dump($this-><FieldName>);
    $GLOBALS[ RecordOwner ] = $this->RequestUser->CurrentValue;  
}

我感到不得不对这一最新情况作出另一种答复。 让我表明使用从<>>>>>>>><>>>>>>中看到的全球知识。 该职能:

$obj->Row_Rendered();
$obj->foobar();

echo $GLOBALS[ RecordOwner ];

Quick,echoed,该数值来自何处? 但这取决于<代码>$obj-foobar()。 也许会改变全球变量。 也许它没有。 谁知道这些变量是否已经确定? 如果没有在每项职能要求之后增加一条解冻线,你将如何追回所发生的事情?

And that s just three lines of code. Imagine that in an application of any complexity.

现在,如果Ireturn,同样的事情也一样。 页: 1 Row_Rendered:

$owner = $obj->Row_Rendered();
$obj->foobar();

echo $owner;

如果<代码>Row_Rendered<>/code> 方法正在按其应当(恢复所有者)行事,则该守则是非常可预测的。 如果你不遵循这一模式,那么,如果申请扩大至任何半途复杂规模时,你就损失了一段时间。

从职能范围内确定变量为全球变量

$my_global_var = "old value";

function doing_stuff(){
  global $my_global_var; //this will use the global variable instead of creating a local one
  $my_global_var = "new value";
}

echo $my_global_var;//returns "new value"




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签