TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-08-2008, 02:30 AM   #1 (permalink)
The Contributor
 
pipesportugal's Avatar
 
Join Date: May 2008
Location: Oporto-Portugal
Posts: 32
Thanks: 11
pipesportugal is on a distinguished road
Default no "include"s inside classes?

Hello everyone,

I just started with OOP and classes and I placed all gets and sets inside an include file and when using the php include keyword get the following error:

Parse error: syntax error, unexpected T_INCLUDE, expecting T_FUNCTION in D:wampwwwform_generatorclass.forms.php on line 187

So, we can not use include files inside a class?

Thanks in advance for all the answers,
pipesportugal
pipesportugal is offline  
Reply With Quote
Old 06-08-2008, 02:34 AM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Can you post lines 185 thru 189 for us to take a look at? You can include a file from near anywhere, and definitely from inside a class.
-m
delayedinsanity is offline  
Reply With Quote
Old 06-08-2008, 03:27 AM   #3 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

He's probably including the files after his variables.
Enfernikus is offline  
Reply With Quote
Old 06-08-2008, 04:17 AM   #4 (permalink)
The Contributor
 
pipesportugal's Avatar
 
Join Date: May 2008
Location: Oporto-Portugal
Posts: 32
Thanks: 11
pipesportugal is on a distinguished road
Default

Hi Thank You so much !

this is what I've done:
include("includes/class_form_sets_e_gets.php");

My logic (which can be wrong newbie logic, of course) was that should be placed after the ending of the function __construct.

Still, I've tried to put it in several different places, beginning, end of the class, etc

The names seem to be all correct.

pipesportugal
pipesportugal is offline  
Reply With Quote
Old 06-08-2008, 08:12 AM   #5 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

It has to be inside the __construct(); -- Classes are wrappers for a collection of properties and methods, all code constructs that are part of them have to be part of one of those methods (the functions) however, and not out and about on their own.
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
pipesportugal (06-08-2008)
Old 06-08-2008, 09:26 AM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You cannot include (or do very much else at all) directly within the body of the class definition, but you can inside methods.

PHP Code:
class Fail {
    
// Generates parse error
    
include 'myfile.php';

    public function 
no_fail()
    {
        
// Perfectly fine to include within a method
        
include 'nofail.php';
    }

Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
pipesportugal (06-08-2008)
Old 06-08-2008, 02:33 PM   #7 (permalink)
The Contributor
 
pipesportugal's Avatar
 
Join Date: May 2008
Location: Oporto-Portugal
Posts: 32
Thanks: 11
pipesportugal is on a distinguished road
Default

Hi thank You so much, I appreciate Your help !

So the way You explained it to me, the problem is solved.

but..., if this is a free (but respectful) opinion forum:

It doesn's have so much logic about it, does it?

An include is a perfectly neutral and static instruction no matter where it is placed.

Since I like to have all my properties defined at the class for a reason of self organization, my cry for help now is where do I put my 23 properties all with:

public function setAction($action)
{
$this->action = $action;
}

public function getAction()
{
return $this->action;
}

It fills up my class text space. In order to see/correct all the other functions, I must scroll and scroll.

When I started working with c# some weeks ago, there was a feature at the visual studio editor very nice which was the possibility of puting 2 marks, one at the beginning and other at the end of the text we wanted to hide, and then we could hide it (it was there, but You couldn't see it, You could see only the mark).

I am presently working with editplus editor which in my opinion is great because it's very light on weight and does what I need an html/php editor has to do, but doesn't seem to have this feature.

Which way can I go ?

Answering this thread is now, not so important as at the beginning, as there are no errors to solve, but I sure would appreciate some suggestions from the most experienced colleagues.

Cheers all,
pipesportugal

Last edited by pipesportugal : 06-08-2008 at 02:36 PM. Reason: mistake
pipesportugal is offline  
Reply With Quote
Old 06-08-2008, 04:28 PM   #8 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

I'm not so much an experienced colleague as more of a rat bastard novice, but it sounds like you may want to check out Dreamweaver. I don't know if Zend does that, but I know for a fact DW does, and all you have to do is select the lines you want 'compressed' and click in the gutter. Honestly though I hardly ever use it myself, but then most of the classes I'm working with in my current project are only 2-400 lines in length, and I've found documenting phpDoc style has really helped with the organization.
-m
delayedinsanity is offline  
Reply With Quote
Old 06-08-2008, 04:58 PM   #9 (permalink)
The Contributor
 
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
SpYkE112 is on a distinguished road
Default

Zend support "code folding" as they call it to, if you have a function, you can folk it op, just like in Visual Studio :)
SpYkE112 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:08 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design