Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
[PHP] Referencing a Class within another Class
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="IntactDev" data-source="post: 263122" data-attributes="member: 24757"><p>Hello DevBest.</p><p></p><p>I'm here today with a topic that has recently come to my attention. I was once trying to do a revamp of my current framework (by adding a secure backend panel). I ran into a loop of death because of this issue.</p><p></p><p>Say I have a class called "cat" and a class called "dog".</p><p></p><p>[PHP]<?php</p><p>class cat {</p><p> function meow() {</p><p> return 'what does the cat say?';</p><p> }</p><p>}</p><p></p><p>class dog {</p><p> function bark() {</p><p> return 'what does the dog say?';</p><p> }</p><p>}</p><p></p><p>new cat = $cat();</p><p>new dog = $dog();</p><p></p><p>class animals {</p><p> function sounds() {</p><p> global cat, dog; #--o here's where the issue starts! o--#</p><p> </p><p> echo $cat->meow() . '<br>' . $dog->bark();</p><p> }</p><p>}</p><p></p><p>?>[/PHP]</p><p></p><p>With more advanced applications, it becomes one big loop when using the global function... What the the other way of calling a function inside another function?</p><p></p><p>@[USER=540]Kryptos[/USER] @[USER=1]RastaLulz[/USER] @[USER=591]Sledmore[/USER] @[USER=6113]Macemore[/USER] @WhoeverElseThatsGoodAtPHP</p></blockquote><p></p>
[QUOTE="IntactDev, post: 263122, member: 24757"] Hello DevBest. I'm here today with a topic that has recently come to my attention. I was once trying to do a revamp of my current framework (by adding a secure backend panel). I ran into a loop of death because of this issue. Say I have a class called "cat" and a class called "dog". [PHP]<?php class cat { function meow() { return 'what does the cat say?'; } } class dog { function bark() { return 'what does the dog say?'; } } new cat = $cat(); new dog = $dog(); class animals { function sounds() { global cat, dog; #--o here's where the issue starts! o--# echo $cat->meow() . '<br>' . $dog->bark(); } } ?>[/PHP] With more advanced applications, it becomes one big loop when using the global function... What the the other way of calling a function inside another function? @[USER=540]Kryptos[/USER] @[USER=1]RastaLulz[/USER] @[USER=591]Sledmore[/USER] @[USER=6113]Macemore[/USER] @WhoeverElseThatsGoodAtPHP [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
[PHP] Referencing a Class within another Class
Top