仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1649|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网页设计References and Aliases are Different...

[复制链接]
不帅 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:21:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
在学习PHP这六个月里,每看到一个优秀的php脚本,就会兴奋的手舞足蹈,嘴里还不停的说:太酷了,太酷了。呵呵,很幼稚吧,但这可能就是兴趣。   References and Aliases are Different Mechanisms  
Author:  zkarakaya  
Date  14/03/2001  
<b>Aliasing and Referencing are completely different mechanisms in PHP.</b>
If you are Java or C++ programmer, you must be careful when using
Objects created on run-time.
<p>
Lets see an example;
<pre>
<?
class MyClass{
   var $myData;
   var $outManager;
    cfunction MyClass($p){
      $this->myData=$p;
      $this->outManager = new MyOutManager($this);
   }
    cfunction display(){
      $this->outManager->display();
   }
}
class MyOutManager{
   var $refObj;
    cfunction MyOutManager(&$obj){
      $this->refObj = &$obj;
   }
    cfunction display(){
      echo $this->refObj->myData;
   }
}
$myvar = new MyClass(10);
$myvar->myData = 20;
$myvar->display();
?>
</pre>
What value be the output of this program code. Many programmer will
say "20", but this is not correct. Output is 10. Why? Because we have
created an instance of MyClass type on the right hand side of assignment
operator, and gave an initial value of 10. In the constructor of MyClass,
we have send the memory location of that newly created instance to another
object of type MyOutManager, and hold this value in $refObj. Now the
reference count for this object is 1, which is $refObf property of
outManager instance. Lets continue the execution. Constructor has finished
its job and returned to assignment operator. PHP4 now creates a new
reference named $myvar to newly created object. Now the reference count
of that object is 2. Be careful that $myvar is not an alies. So that when
you execute the next statement, which assigns a value 20 to its property
named $myData, PHP4 creates a new instance of MyClass type, copies
the contents of old one which is also referenced by its member outManager.
And then changes the contents of myData to 20.
<p>
>From now on you will have two different instance of type MyClass.
Our intend was not this. So to correct this problem, use alias
on the object creation statement, that is use;
<pre>
$myvar = &new MyClass(10);
</pre>
This will solve the problem. So if you are C++ and Java programmer,
you must be careful in writing PHP codes.
<p>
This description does not conflict with the information given in the
<a href="http://www.zend.com/zend/art/ref-count.php"> PHP 4: Reference
Counting and Aliasing</a>
written by <a href="http://www.zend.com/comm_person.php?id=6" >Andi
Gutmans.</a>
<p>
Ziya Karakaya

  因为函数实在是太多了,慢慢的你就会知道,知道有这个函数就可以。
山那边是海 该用户已被删除
沙发
发表于 2015-2-4 12:08:18 | 只看该作者
首先我是坚决反对新手上来就用框架的,因为对底层的东西一点都不了解,造成知识上的真空,会对以后的发展不利。我的观点上手了解下框架就好,代码还是手写。当然啦如果是位别的编程语言的高手的话,这个就另当别论啦。
金色的骷髅 该用户已被删除
板凳
发表于 2015-2-8 21:33:46 | 只看该作者
环境搭建好,当你看见你的浏览器输出“it works\\\\\\\"时你一定是喜悦的。在你解决问题的时候,我强烈建议多读php手册。
变相怪杰 该用户已被删除
地板
发表于 2015-3-1 08:20:14 | 只看该作者
当然这种网站的会员费就几十块钱。
透明 该用户已被删除
5#
发表于 2015-3-2 19:48:15 | 只看该作者
我要在声明一下:我是个菜鸟!!我对php这门优秀的语言也是知之甚少。但是我要在这里说一下php在网站开发中最常用的几个功能:
6#
发表于 2015-3-4 03:13:48 | 只看该作者
在学习的过程中不能怕麻烦,不能有懒惰的思想。学习php首先应该搭建一个lamp环境或者是wamp环境。这是学习php开发的根本。虽然网络上有很多集成的环境,安装很方便,使用起来也很稳定、
愤怒的大鸟 该用户已被删除
7#
发表于 2015-3-11 08:07:01 | 只看该作者
装在C盘下面可以利用windows的ghost功能可以还原回来(顺便当做是重转啦),当然啦我的编译目录要放在别的盘下,不然自己的劳动成果就悲剧啦。
柔情似水 该用户已被删除
8#
发表于 2015-3-17 23:38:44 | 只看该作者
Apache不是非得用80或者8080端口的,我刚开始安得时候就是80端口老占用,就用了个 81端口,结果照常,就是输localhost的时候,应该输入为 localhost:81
再见西城 该用户已被删除
9#
发表于 2015-3-22 01:09:25 | 只看该作者
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
若相依 该用户已被删除
10#
发表于 2015-3-25 10:09:55 | 只看该作者
实践是检验自己会不会的真理。
只想知道 该用户已被删除
11#
发表于 2015-3-25 20:34:42 | 只看该作者
我要在声明一下:我是个菜鸟!!我对php这门优秀的语言也是知之甚少。但是我要在这里说一下php在网站开发中最常用的几个功能:
小妖女 该用户已被删除
12#
发表于 2015-3-27 09:09:48 | 只看该作者
对于懒惰的朋友,我推荐php的集成环境xampp或者是wamp。这两个软件安装方便,使用简单。但是我还是强烈建议自己动手搭建开发环境。
小女巫 该用户已被删除
13#
发表于 2015-3-27 12:08:59 | 只看该作者
找到的的资料很多都是在论坛里的,需要注册,所以我一般没到一个论坛都注册一个id,所有的id都注册成一样的,这样下次再进来的时候就不用重复注册啦。当然有些论坛的某些资料是需要的付费的。
飘灵儿 该用户已被删除
14#
发表于 2015-3-31 20:46:22 | 只看该作者
开发工具也会慢慢的更专业,每个公司的可能不一样,但是zend studio是个大伙都会用的。
活着的死人 该用户已被删除
15#
发表于 2015-4-3 20:38:01 | 只看该作者
装在C盘下面可以利用windows的ghost功能可以还原回来(顺便当做是重转啦),当然啦我的编译目录要放在别的盘下,不然自己的劳动成果就悲剧啦。
冷月葬花魂 该用户已被删除
16#
发表于 2015-4-10 21:14:44 | 只看该作者
实践是检验自己会不会的真理。
再现理想 该用户已被删除
17#
发表于 2015-4-11 19:03:50 | 只看该作者
要进行开发,搭建环境是首先需要做的事,windows下面我习惯把环境那个安装在C盘下面,因为我配的环境经常出现诡异事件,什么事都没做环境有的时候就不能用啦。
老尸 该用户已被删除
18#
发表于 2015-4-16 19:47:55 | 只看该作者
使用 jquery 等js框架的时候,要随时注意浏览器的更新情况,不然很容易发生框架不能使用。
深爱那片海 该用户已被删除
19#
发表于 2015-5-2 18:52:58 | 只看该作者
再就是混迹于论坛啦,咱们的phpchina的论坛就很强大,提出的问题一般都是有达人去解答的,以前的帖子也要多看看也能学到不少前辈们的经验。别的不错的论坛例如php100,javaeye也是很不错的。
灵魂腐蚀 该用户已被删除
20#
发表于 2015-5-4 13:21:57 | 只看该作者
我学习了一段时间后,我发现效果并不好(估计是我自身的问题)。因为一个人的精力总是有限的,同时学习这么多,会导致每个的学习时间都得不到保证。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-9-20 21:17

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表