note 46239 added to function.return

From: Date: Mon, 04 Oct 2004 04:52:24 +0000
Subject: note 46239 added to function.return
Groups: php.notes 
Request: Send a blank email to php-notes+get-77872@lists.php.net to get a copy of this message
<? /* The problem of the use of the include function was the impossibility of the use of call to another function / variables from the same class and the call of the return don't make any result. When you call in the place of {include("Poo2.php");} the {return include("Poo2.php")} all the properties of the object could in such a way be used if having free access to the functions as to the variaveis. This process is very good for best use of classes that contains many big functions. The classes becomes an small archive and the functions are create but the code of the same ones is only loaded when this will be to be executed. The access if becomes fast more without if having the loss of resources '$this - > ' and ' return ' Another advantage of this resource is to make possible that two independent classes can include the same function. But, when this function will to make the use of the other functions / variables interns the classes, then it will go to work in different ways. With this organization you can even simulate a multiple inheritances (although I not to recommend this) */ /* O problema de se usar a função include era a impossibilidade do uso de chamadas de outras funções / variaveis da mesma classe e a chamada do return não executava nenhuma ação. Quando se chama ao invez de apenas include("Poo2.php");} o {return include("Poo2.php")} todas as propriedades do objeto poderão ser utilizadas se tendo livre acesso tanto às funções quanto às variaveis. Este processo é muito util na otimização de classes com muitas funções grandes. A classe se torna um arquivo pequeno e as funções são criadas mas o código das mesmas só é carregado quando esta for ser executada. O acesso se torna mais rápido sem se ter a perda de recursos '$this->' e 'return'. Outra vantagem deste recurso é possibilitar que duas classes independentes possam incluir a mesma função mas quando esta função for fazer o uso das outras funções / variaveis internas a classe funcionará de maneiras diferentes. Com este recurso você pode até simular heranças multiplas (apesar de eu não recomendar isso) */ ?> <? /* Poo1.php */ class People { var $Name = ''; function SayHello($Him) {return "<b> Hello ".$Him."! <br> </b>";} function Introduce() {return "<b> Hi, my name is ".$this->Name." <br> </b>";} function Meet($People) { // include("Poo2.php"); //\\ Não funcinará! //\\ Don't will work! //\\ return include("Poo2.php"); //\\ Funcinária perfeitamente //\\ Will works just fine //\\ } } class Dog { var $Name = ''; function SayHello($Him) {return "<b> I go to sneak the $Him ! <br> </b>";} function Introduce() {return "<b> Au ! <br> </b>";} function Meet($People) {return include("Poo2.php");} //\\ A mesma função! //\\ The same function //\\ } $He = new People; $He->Name = 'Bob'; print "The Bob say... <br>"; print $He->Meet('Bob'); print $He->Meet('Marie'); print "<BR>"; $It = new Dog; $It->Name = 'Snoopy'; print "The Snoopy say... <br>"; print $It->Meet('Snoopy'); print $It->Meet('Marie'); ?> <? /* Poo2.php */ if ($People == $this->Name) {return $this->Introduce();} else {return $this->SayHello($People);} ?> OUTPUT: The Bob say... Hi, my name is Bob Hello Marie! The Snoopy say... Au ! I go to sneak the Marie ! ---- Manual Page -- http://www.php.net/manual/en/function.return.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46239 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46239&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46239&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77872) next »