English 中文(简体)
当页上张贴时,不更新物品
原标题:property not updating in object when page is posted
  • 时间:2010-06-16 01:32:13
  •  标签:
  • php
  • oop

我将财产放在类似建筑的建筑中。

function __construct()
{

$this->count = count(@$_SESSION[ filearray ]); //count how many files in array
}

在情况说明中加以使用:if ($this->count > 10) /then do some

但是,在我用另一种注射价值方法进入这一档案时,该数字似乎还没有更新。

我是否做了一些错误? 我认为,我的施工人员将发现本届会议发生了变化,每当我打电话一美元“thi”时,我就拿到目前的计值,但看来是在我重新启用该页之前的一步。

如果这完全含糊不清,我可以包括我的表格页,该页有所有的方法,但这是我的问题的主人,为什么我的财产没有更新,我如何确定:

TIA

最佳回答

<代码>$this->count在案卷上每增加一次或减去一次时自动更新。 只有在当值班或直接打电话时才援引教员。

你们可以通过一个接驳器实现这种功能。

class myClass {
  public function getCount() {
    return count(@$_SESSION[ filearray ]);
  }
}

$_SESSION[ filearray ] = array( bar );
$foo = new myClass();
echo $foo->getCount(); // 1

或使用magic-method:

class myClass {

  public function __get($property_name) {
    if ($property_name ==  count ) {
      return count(@$_SESSION[ filearray ]);
    }
  }
}

$_SESSION[ filearray ] = array( bar );
$foo = new myClass();
echo $foo->count; // 1    

或两者结合:

class myClass {

  private $_count;

  public function __get($property_name) {
    if ($property_name ==  count ) {
      return $this->_getCount();
    }
  }

  private function _getCount() {
    return $this->_count = count(@$_SESSION[ filearray ]);
  }
}

$_SESSION[ filearray ] = array( bar );
$foo = new myClass();
echo $foo->count; // 1
问题回答

暂无回答




相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签