English 中文(简体)
课堂内使用的卫生套课程
原标题:PHP classes used within classes?
  • 时间:2011-10-01 13:27:08
  •  标签:
  • php
  • class

我的理解是,$something->Function();指的是某一类别中的职能,但“代码”究竟是什么?

最佳回答

我假定你指的是<条码>$->somethingelse->Function()。

也就是说,<代码>(tthing>,名称为$somethingelse的财产是另一个有功能(>的物体。

$something = new Class1();
$something->somethingelse = new Class2();  // Class2 has the "function()" method


// Now I can call...
$something->somethingelse->function();
问题回答

你可以这样说:

class foo {
  public $bar;
}

class bar {
  public $baz;
}

class baz {
  function blip() { echo "Hello World"; }
}

$foo = new foo();
$foo->bar = new bar(); // setting bar to new object
$foo->bar->baz = new baz(); // setting baz to new object
$foo->bar->baz->blip(); // calling the blip function

例常数中包含一种称为some的事例变量,也是标的(一等)。

它被认为是一种坏的做法(见Law of Deile on Wikipedia )。

http://c2.com/cgi/wiki?LawOfDeif"rel=“nofollow” Peter Van Rooijen的2.com标准法是:

你可以 yourself。

你可以自己做事(但你可以把他们分开)。

你可以与你们的玩具打交道。

你可以与你 yourself的玩具打交道。

英语简便:

你的方法可以直接在其类别中采用其他方法。

你的方法可以直接在自己的领域(而不是在田里)使用方法。

如果你的方法具有参数,你的方法可以直接使用这些参数。

When your method creates local objects, that method can call methods on the local objects.

BUT

不应将方法称作全球目标。

不应在某类人以外的某些类别有电线链。

另一个有趣的读物是:, 采用较为严格的方法。





相关问题
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 ...

热门标签