variables in the includes – PHP

  php

Q(Question):

I hate to ask an obvious question but I’m trying not to mess up
anything worse than it is already. I have all these variables in-
line. Can I do an include and take them off the file into an included
file?

$with_reserve = $sessionVars["SELL_with_reserve"];
$reserve_price = $sessionVars["SELL_reserve_price"];
$minimum_bid = $sessionVars["SELL_minimum_bid"];
$pict_url=$sessionVars["SELL_pict_url"];
$imgtype = $sessionVars["SELL_file_uploaded"];
$title = $sessionVars["SELL_title"];
$description = $sessionVars["SELL_description"];
$pict_url = $sessionVars["SELL_pict_url"];
$atype = $sessionVars["SELL_atype"];
$adultonly = $sessionVars["SELL_adultonly"];
$iquantity = $sessionVars["SELL_iquantity"];
$buy_now = $sessionVars["SELL_with_buy_now"];
$buy_now_price = $sessionVars["SELL_buy_now_price"];
$duration = $sessionVars["SELL_duration"];
$relist = $sessionVars["SELL_relist"];
$increments = $sessionVars["SELL_increments"];
$customincrement = $sessionVars["SELL_customincrement"];
$country = $sessionVars["SELL_country"];
$location_zip = $sessionVars["SELL_location_zip"];
$shipping = $sessionVars["SELL_shipping"];
$shipping_terms = $sessionVars["SELL_shipping_terms"];
$payment = $sessionVars["SELL_payment"];
$international = ($sessionVars["SELL_international"])?"on":"";
$sellcat = $_SESSION[‘sellcat’];
$invitedlists = $sessionVars["SELL_invitedlists"];
$private = $sessionVars["SELL_private"];
if($private != ‘y’) $private = ‘n’;
$sendemail = $sessionVars["SELL_sendemail"];
$blacklists = $sessionVars["SELL_blacklists"];
$txt = $sessionVars["SELL_txt"];
$num = $sessionVars["SELL_num"];
$buy_now_only = $sessionVars["SELL_buy_now_only"];
Here are my includes:

include ‘./includes/config.inc.php’;
include $include_path.’dates.inc.php’;
include $include_path.’auction_types.inc.php’;
include $include_path.’countries.inc.php’;
include $include_path.’datacheck.inc.php’;
include $include_path.’wordfilter.inc.php’;
include $include_path.’converter.inc.php’;
include $include_path.’functions.inc.php’;
So would it be something like:
include $include_path.’variables.inc.php’;
assuming it is in the includes directory?

thanks you have been a great help.

A(Answer):

JRough a écrit :

I hate to ask an obvious question but I’m trying not to mess up
anything worse than it is already. I have all these variables in-
line. Can I do an include and take them off the file into an included
file?

Not really clean, but yes you can do it.
Include file is some kind of seperation to make your code cleaner, and
to avoid duplicate functions/portions. But it works just as is the
included file content was copied/pasted in place of the include function.

Though, I said not really clean, cause it’s not easy for maintainers
afterward to keep track of everything if there is functions somewhere,
variables somewhere else, defines here, config there… Usually I would
hate having variables somewhere else.

Regards

Guillaume

A(Answer):

On May 13, 9:11 am, Guillaume <ggra…@NOSPAM.gmail.com.INVALID>
wrote:

JRough a écrit :

I hate to ask an obvious question but I’m trying not to mess up
anything worse than it is already. I have all these variables in-
line. Can I do an include and take them off the file into an included
file?

Not really clean, but yes you can do it.
Include file is some kind of seperation to make your code cleaner, and
to avoid duplicate functions/portions. But it works just as is the
included file content was copied/pasted in place of the include function.

Though, I said not really clean, cause it’s not easy for maintainers
afterward to keep track of everything if there is functions somewhere,
variables somewhere else, defines here, config there… Usually I would
hate having variables somewhere else.

Regards

Guillaume

Okay, does that mean you leave the functions in-line also?

A(Answer):

On May 13, 9:11 am, Guillaume <ggra…@NOSPAM.gmail.com.INVALID>
wrote:

JRough a écrit :

I hate to ask an obvious question but I’m trying not to mess up
anything worse than it is already. I have all these variables in-
line. Can I do an include and take them off the file into an included
file?

Not really clean, but yes you can do it.
Include file is some kind of seperation to make your code cleaner, and
to avoid duplicate functions/portions. But it works just as is the
included file content was copied/pasted in place of the include function.

Though, I said not really clean, cause it’s not easy for maintainers
afterward to keep track of everything if there is functions somewhere,
variables somewhere else, defines here, config there… Usually I would
hate having variables somewhere else.

Regards

Guillaume

Actually that makes sense, an include would be for functions that are
repeated not just called once. The problem is I am trying to organize
something htat needs to be rewritten. Their probably are functions
that should be written better.
thanks,

A(Answer):

Greetings, JRough.
In reply to Your message dated Tuesday, May 13, 2008, 20:31:20,

I hate to ask an obvious question but I’m trying not to mess up
anything worse than it is already. I have all these variables in-
line. Can I do an include and take them off the file into an included
file?

Not really clean, but yes you can do it.
Include file is some kind of seperation to make your code cleaner, and
to avoid duplicate functions/portions. But it works just as is the
included file content was copied/pasted in place of the include function.

Though, I said not really clean, cause it’s not easy for maintainers
afterward to keep track of everything if there is functions somewhere,
variables somewhere else, defines here, config there… Usually I would
hate having variables somewhere else.

Actually that makes sense, an include would be for functions that are
repeated not just called once. The problem is I am trying to organize
something htat needs to be rewritten. Their probably are functions
that should be written better.
thanks,

Then think about it as when You’re doing Your house cleanup.
1. Classify things.
2. Arrange them by some attributes.
3. Separate and store them depends on the arrangement.

Sincerely Yours, AnrDaemon <an*******@freemail.ru>

A(Answer):

On 13 May, 15:37, JRough <jlro…@yahoo.comwrote:

I hate to ask an obvious question but I’m trying not to mess up
anything worse than it is already. I have all these variables in-
line. Can I do an include and take them off the file into an included
file?

$with_reserve = $sessionVars["SELL_with_reserve"];
$reserve_price = $sessionVars["SELL_reserve_price"];
$minimum_bid = $sessionVars["SELL_minimum_bid"];
$pict_url=$sessionVars["SELL_pict_url"];
$imgtype = $sessionVars["SELL_file_uploaded"];
$title = $sessionVars["SELL_title"];
$description = $sessionVars["SELL_description"];
$pict_url = $sessionVars["SELL_pict_url"];
$atype = $sessionVars["SELL_atype"];
$adultonly = $sessionVars["SELL_adultonly"];
$iquantity = $sessionVars["SELL_iquantity"];
$buy_now = $sessionVars["SELL_with_buy_now"];
$buy_now_price = $sessionVars["SELL_buy_now_price"];
$duration = $sessionVars["SELL_duration"];
$relist = $sessionVars["SELL_relist"];
$increments = $sessionVars["SELL_increments"];
$customincrement = $sessionVars["SELL_customincrement"];
$country = $sessionVars["SELL_country"];
$location_zip = $sessionVars["SELL_location_zip"];
$shipping = $sessionVars["SELL_shipping"];
$shipping_terms = $sessionVars["SELL_shipping_terms"];
$payment = $sessionVars["SELL_payment"];
$international = ($sessionVars["SELL_international"])?"on":"";
$sellcat = $_SESSION[‘sellcat’];
$invitedlists = $sessionVars["SELL_invitedlists"];
$private = $sessionVars["SELL_private"];
if($private != ‘y’) $private = ‘n’;
$sendemail = $sessionVars["SELL_sendemail"];
$blacklists = $sessionVars["SELL_blacklists"];
$txt = $sessionVars["SELL_txt"];
$num = $sessionVars["SELL_num"];
$buy_now_only = $sessionVars["SELL_buy_now_only"];

Here are my includes:

include ‘./includes/config.inc.php’;
include $include_path.’dates.inc.php’;
include $include_path.’auction_types.inc.php’;
include $include_path.’countries.inc.php’;
include $include_path.’datacheck.inc.php’;
include $include_path.’wordfilter.inc.php’;
include $include_path.’converter.inc.php’;
include $include_path.’functions.inc.php’;

So would it be something like:
include $include_path.’variables.inc.php’;

assuming it is in the includes directory?

thanks you have been a great help.

An include file would be better, but extract() might be a simpler/
faster/neater solution.

C.

A(Answer):

JRough a écrit :

Okay, does that mean you leave the functions in-line also?

Usually my structure is this one:
– functions.inc.php contains all my functions except the ones I use only
on a specific page
– config.inc.php contains the server configuration (basedir, default
skin, etc…) and the constants
– connect.inc.php contains the DB parameters
– session.inc.php whenever I use them

That’s all, everything else, including variables definitions, goes in
the code, where they are supposed to be used.

Regards,

Guillaume

LEAVE A COMMENT