The code is blelow;
-----------------b.php----------------
<?php
function __autoload($class_name) {
include_once $class_name . '.php';
}
$objref=new My("Good");
$objref->buff();
?>
-----------------------------------
----------My.php--------------
<?php
$obj=new My("Hello");
$obj->buff();
Class My{
private $word;
function __construct($getword){
$this->word=$getword;
}
public function buff(){
echo $this->word."<br />";
}
}
?>
--------------------------------------
on website, first it execute My.php , then execute b.php
So it will show blelow;
Hello(when excute My.php)
Hello(when excute from b.php)
Good(when excute from b.php)
I do not need "Hello" twice
I would get
Hello(when excute My.php)
Good(when excute from b.php)
Please do help me!
Regards,
Yui
2008/6/3 Thijs Lensselink <[EMAIL PROTECTED]>:
> Quoting Yui Hiroaki <[EMAIL PROTECTED]>:
>
>> Please look at my.php
>>
>> my.php load
>> $obj=new My("Hello");
>> $obj->buff();
>>
>> so, if a.php load, it absolutely got "hello" in load b.php
>>
>> Regards,
>> Yui
>>
>> 2008/6/3 Thijs Lensselink <[EMAIL PROTECTED]>:
>>>
>>> Quoting Yui Hiroaki <[EMAIL PROTECTED]>:
>>>
>>>> Thank you for a good suggest!
>>>>
>>>> Somehow, I have to execute my.php also.
>>>> This program have to run.
>>>> 1)My.php
>>>> 2)b.php
>>>>
>>>> My.php show "Hello" -> it is OK,
>>>> b.php shows
>>>> "Hello"
>>>> "Good"
>>>>
>>>> it is NOT good. I need to get only "Good"
>>>>
>>>>
>>>> Please give me a suggestion.
>>>>
>>>> Regards,
>>>> Yui
>>>> 2008/6/3 James Dempster <[EMAIL PROTECTED]>:
>>>>>
>>>>> I suggest you don't put code other than class structures in class
>>>>> files.
>>>>> Also don't execute My.php just execute b.php which though __autoload
>>>>> includes My.php.
>>>>>
>>>>> -----------------b.php----------------
>>>>> <?php
>>>>> function __autoload($class_name) {
>>>>> include_once $class_name . '.php';
>>>>> }
>>>>>
>>>>> $obj=new My("Hello");
>>>>> $obj->buff();
>>>>>
>>>>> $objref=new My("Good");
>>>>> $objref->buff();
>>>>>
>>>>> -----------------------------------
>>>>>
>>>>> ----------My.php--------------
>>>>> <?php
>>>>>
>>>>> Class My{
>>>>> private $word;
>>>>> function __construct($getword){
>>>>> $this->word=$getword;
>>>>> }
>>>>> public function buff(){
>>>>> echo $this->word."<br />";
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>> /James Dempster
>>>>>
>>>>> On Tue, Jun 3, 2008 at 9:17 AM, Yui Hiroaki <[EMAIL PROTECTED]>
>>>>> wrote:
>>>>>>
>>>>>> HI!
>>>>>>
>>>>>> I had mistake in code in php.
>>>>>>
>>>>>> When I excute My.php, it say "Hello"
>>>>>> When I excute b.php, it say
>>>>>> Hello
>>>>>> Good
>>>>>>
>>>>>> I would like to execute b.php and show
>>>>>> only "Good"
>>>>>>
>>>>>> If you know it ,please teach me!
>>>>>>
>>>>>> Here is code below;
>>>>>>
>>>>>> -----------------b.php----------------
>>>>>> <?php
>>>>>> function __autoload($class_name) {
>>>>>> include_once $class_name . '.php';
>>>>>> }
>>>>>>
>>>>>>
>>>>>> $objref=new My("Good");
>>>>>> $objref->buff();
>>>>>> ?>
>>>>>> -----------------------------------
>>>>>>
>>>>>> ----------My.php--------------
>>>>>> <?php
>>>>>> $obj=new My("Hello");
>>>>>> $obj->buff();
>>>>>>
>>>>>>
>>>>>> Class My{
>>>>>> private $word;
>>>>>> function __construct($getword){
>>>>>> $this->word=$getword;
>>>>>> }
>>>>>> public function buff(){
>>>>>> echo $this->word."<br />";
>>>>>> }
>>>>>> }
>>>>>> ?>
>>>>>> --------------------------------------
>>>>>> Regards,
>>>>>> Yui
>>>>>>
>>>>>>
>>>>>> 2008/6/3 James Dempster <[EMAIL PROTECTED]>:
>>>>>> > I don't see how it's possible for you to get "Hello" after "Good",
>>>>>> > when
>>>>>> > the
>>>>>> > file that cause's "Hello" is required to do "Good"
>>>>>> >
>>>>>> > /James
>>>>>> >
>>>>>> > On Mon, Jun 2, 2008 at 2:00 PM, Yui Hiroaki <[EMAIL PROTECTED]>
>>>>>> > wrote:
>>>>>> >>
>>>>>> >> Please take a look at code.
>>>>>> >>
>>>>>> >> --------a.php--------
>>>>>> >>
>>>>>> >> $obj=new my("Hello");
>>>>>> >> $obj->buff();
>>>>>> >>
>>>>>> >>
>>>>>> >> Class my{
>>>>>> >>
>>>>>> >> private $word;
>>>>>> >> function __construct($getword){
>>>>>> >> $this->word=$getword;
>>>>>> >> }
>>>>>> >> public function buff(){
>>>>>> >> echo $this->word."<br />";
>>>>>> >> }
>>>>>> >> --------------------------------------
>>>>>> >>
>>>>>> >>
>>>>>> >> -----b.php-----------------------
>>>>>> >>
>>>>>> >> function __autoload($class_name) {
>>>>>> >> include_once $class_name . '.php';
>>>>>> >> }
>>>>>> >>
>>>>>> >>
>>>>>> >> $objref=new my("Good");
>>>>>> >> $objref->buff();
>>>>>> >> --------------------------------------------
>>>>>> >>
>>>>>> >>
>>>>>> >>
>>>>>> >> I get an Echo;
>>>>>> >>
>>>>>> >> Good
>>>>>> >> Hello
>>>>>> >> Hello
>>>>>> >>
>>>>>> >> I do not need to get Hello twice.
>>>>>> >>
>>>>>> >> When I b.php , $obj=new my("Hello") is loaded.
>>>>>> >>
>>>>>> >>
>>>>>> >> Do you have any adia to avoid load $obj in a.php twice?
>>>>>> >>
>>>>>> >> Regards,
>>>>>> >> Yui
>>>>>> >>
>>>>>> >> --
>>>>>> >> PHP General Mailing List (http://www.php.net/)
>>>>>> >> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>> >>
>>>>>> >
>>>>>> >
>>>>>
>>>>>
>>>>
>>>> --
>>>> PHP General Mailing List (http://www.php.net/)
>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>
>>>>
>>>
>>>
>>> If you only want to see "Good" Then don't run it twice.
>>> Take James's suggestion and try it again:
>>>
>>> -----------------b.php----------------
>>> <?php
>>> function __autoload($class_name) {
>>> include_once $class_name . '.php';
>>> }
>>>
>>> $objref=new My("Good");
>>> $objref->buff();
>>>
>>> -----------------------------------
>>>
>>> ----------My.php--------------
>>> <?php
>>>
>>> Class My{
>>> private $word;
>>> function __construct($getword){
>>> $this->word=$getword;
>>> }
>>> public function buff(){
>>> echo $this->word."<br />";
>>> }
>>> }
>>>
>>>
>
> I don't think i understand you fully. Or you're trying to make it to
> complicated.
>
> You have a class in "My.php" :
>
> Class My{
> private $word;
>
> function __construct($getword){
> $this->word=$getword;
> }
>
> public function buff(){
> echo $this->word."<br />";
> }
> }
>
> And a script that creates an instance of My "b.php" :
>
> function __autoload($class_name) {
> include_once $class_name . '.php';
> }
>
> $obj=new My("Hello");
> $obj->buff();
>
> $objref=new My("Good");
> $objref->buff();
>
> The output will be "Hello<br/>Good<br/>". because you call it two times. So
> if you only want to see "Good". Then you change "b.php" to look like this:
>
> function __autoload($class_name) {
> include_once $class_name . '.php';
> }
>
> $objref=new My("Good");
> $objref->buff();
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php