PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 27th, 2012, 08:03 AM
maximas maximas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 29 maximas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 22 m 30 sec
Reputation Power: 0
PHP-OOP - How to use in the other function the variable in function

hi,

PHP Code:
<?php 

class index 
    

        function 
foo()
            {
                
                
$val="bar";
                
                
            }
            
}

        class 
index2 extends index 
        
                function 
bar ()
                    {
                        
                        echo 
$val;
                        
                    }
                    
        }
            
        

$dir=new index2();
echo 
$dir->bar();

?>



variable in that foo method, I want to use in class of bar method being extends

but it does not work...

how to use?

Reply With Quote
  #2  
Old October 27th, 2012, 09:55 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,847 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 10 h 36 m 10 sec
Reputation Power: 813
Hi,

this doesn't make sense. First of all, $val is a local variable. It isn't visible anywhere except for this specific function while it's running. I guess what you actually want is an attribute. Secondly, even if this was an attribute, you'd need to call foo() to even set the attribute to "bar". Before you'll just get null.

I think you should look into the OOP basics again. A working example would be

PHP Code:
<?php

class {

    public 
$var 'bar';

}

class 
extends {

    public function 
bar() {
        echo 
$this->var;
    }

}

$a = new B();
$a->bar();

Reply With Quote
  #3  
Old October 27th, 2012, 03:33 PM
maximas maximas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 29 maximas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 22 m 30 sec
Reputation Power: 0
thanks jacguies

I suppose that I dont know the php classes...like that you said, I should work this about.

Reply With Quote
  #4  
Old December 6th, 2012, 06:58 AM
diyaots diyaots is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 117 diyaots Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 29 m 41 sec
Reputation Power: 0
Find the solutions of your problem.

Comments on this post
Jacques1 disagrees: Dear friend, please stop posting useless "solutions" and learn to use code tags (after 1 1/2 years
and 100 posts).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-OOP - How to use in the other function the variable in function

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap