PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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 September 3rd, 2007, 07:42 PM
topgear24 topgear24 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Location: toronto
Posts: 11 topgear24 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 21 m 10 sec
Reputation Power: 0
PHP5 - Including php script within class function

This isn't so much a question of why something doesn't work, but rather a question of why it does work. Using PHP you can include scripts from within class functions and access the included functions globally. This surprises me, it seems to go against what I feel should occur. If someone has a sound reason why this occurs, I would appreciate it.

temp_include.php:
PHP Code:
<?php

function test_funct() {
    echo 
"function called";
}

?>


main script:
PHP Code:
<?php

Class ABC {
    public function 
__construct() {
        require_once 
'temp_include.php';
    }
}

$o = new ABC();

test_funct();

?>

Reply With Quote
  #2  
Old September 3rd, 2007, 07:59 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,565 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 8 h 50 m 47 sec
Reputation Power: 379
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
maybe you can, but the concept is incorrect.. meaning it was not created to work this way.. and things that have not been created to work away... leads to vulnerabilities sometimes.

Reply With Quote
  #3  
Old September 3rd, 2007, 08:00 PM
requinix's Avatar
requinix requinix is online now
No strings attached
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 4,622 requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)requinix User rank is General 13rd Grade (Above 100000 Reputation Level)  Folding Points: 76305 Folding Title: Intermediate FolderFolding Points: 76305 Folding Title: Intermediate FolderFolding Points: 76305 Folding Title: Intermediate FolderFolding Points: 76305 Folding Title: Intermediate Folder
Time spent in forums: 3 Months 3 Weeks 3 Days 19 h 15 m
Reputation Power: 1872
Send a message via MSN to requinix
http://us2.php.net/manual/en/language.functions.php
Quote:
Originally Posted by PHP Manual
All functions and classes in PHP have the global scope - they can be called outside a function even if they were defined inside and vice versa.

All you're doing is defining a function inside a function: the fact that it's inside a class too doesn't matter.
__________________
How to ask a question

Reply With Quote
  #4  
Old September 3rd, 2007, 08:06 PM
topgear24 topgear24 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Location: toronto
Posts: 11 topgear24 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 21 m 10 sec
Reputation Power: 0
Yeah, it seems to be somewhat common practice to include this way anyways. I took a look at the source for Smarty and their Smarty_compiler.class.php includes plugins and other files from functions of that class this way.

Reply With Quote
  #5  
Old September 3rd, 2007, 08:30 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Contributing User
Click here for more information.
 
Join Date: Dec 2004
Posts: 2,515 E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 2 Days 2 h 50 m
Reputation Power: 1170
Quote:
maybe you can, but the concept is incorrect.. meaning it was not created to work this way.. and things that have not been created to work away... leads to vulnerabilities sometimes.

According to the manual it was created to work that way. If it didn't work that way it would be possible to dynamically add functions to an object; I don't know for sure but I'm pretty sure that doing something like that would requires pretty extensive design changes to the zend engine. Not that it would be a bad thing (javascript supports it and imo javascript's class system is one of the best with the exception of a few small parts of it), but I don't think PHP even could support something like that in its current state.

Reply With Quote
  #6  
Old September 3rd, 2007, 08:34 PM
chadsmith729's Avatar
chadsmith729 chadsmith729 is offline
--Retired--
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Sep 2003
Location: Enjoying forum retirement.
Posts: 3,117 chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 17 h 33 m 9 sec
Reputation Power: 1020
Ok, off topic question is now: Do you really need to use a class for this or are you just curious?

Chad
__________________
Get A Supplier LLC | Hilarious Comic

--- Pretty much retired from the forum. I will get back on every now and then, and maybe answer a few questions.

Reply With Quote
  #7  
Old September 3rd, 2007, 08:43 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Contributing User
Click here for more information.
 
Join Date: Dec 2004
Posts: 2,515 E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 2 Days 2 h 50 m
Reputation Power: 1170
You don't need to use a class for this. The OP was commenting it was was odd that when you include a file within the scope of a class the functions in the included file are added to the global scope rather than the class scope (as they would if the methods had been hard coded into the class).

Reply With Quote
  #8  
Old September 3rd, 2007, 08:53 PM
topgear24 topgear24 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Location: toronto
Posts: 11 topgear24 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 21 m 10 sec
Reputation Power: 0
Quote:
Originally Posted by chadsmith729
Ok, off topic question is now: Do you really need to use a class for this or are you just curious?

Chad


For reasons I won't get into, I'm considering of setting up a plugin system into my application. So yeah, this wasn't just something that popped in my head while watching the Jays getting killed.

Reply With Quote
  #9  
Old September 3rd, 2007, 09:04 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Contributing User
Click here for more information.
 
Join Date: Dec 2004
Posts: 2,515 E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 3rd Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 2 Days 2 h 50 m
Reputation Power: 1170
Quote:
You don't need to use a class for this. The OP was commenting it was was odd that when you include a file within the scope of a class the functions in the included file are added to the global scope rather than the class scope (as they would if the methods had been hard coded into the class).


Sorry I misunderstood chadsmith's question, I thought he was asking if you needed a class to use include ><

Reply With Quote
  #10  
Old September 3rd, 2007, 09:19 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,565 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1Folding Points: 111202 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 8 h 50 m 47 sec
Reputation Power: 379
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Quote:
Originally Posted by E-Oreo
According to the manual it was created to work that way. If it didn't work that way it would be possible to dynamically add functions to an object; I don't know for sure but I'm pretty sure that doing something like that would requires pretty extensive design changes to the zend engine. Not that it would be a bad thing (javascript supports it and imo javascript's class system is one of the best with the exception of a few small parts of it), but I don't think PHP even could support something like that in its current state.
hmm like I said before.. you probably can (as it looks like you can) but.. It does not sound like something I would prefer doing.. in other words.. I my self would not trust calling a function in that manner.. now using $var -> classconstfunc this way I would.

Reply With Quote
  #11  
Old September 4th, 2007, 06:53 AM
chadsmith729's Avatar
chadsmith729 chadsmith729 is offline
--Retired--
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Sep 2003
Location: Enjoying forum retirement.
Posts: 3,117 chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1Folding Points: 293486 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 17 h 33 m 9 sec
Reputation Power: 1020
Topgear:

Ok that's fine, I just had to question that. Because maybe there was another way that you could be doing the project that might be easier and better to maintain.

Great, have a good time and hope you find an answer.
Chad

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Including php script within class function


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



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT