Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Confused About Scope Of Globals In Included Files


I'm having an issue where what should be global variables are not in
scope and I'm confused as to why.

In Case 1 the variables are not in scope for functions in File2
In Case 2 the varibales are in scope for access in File1's functions
AFTER the include
In Case 3 the varibales are in scope for functionsin File2


Why does case 1 not work but case 3 does? Does case 2 the proper method
to use?

CASE 1:.........




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Variable Scope Of Files Included Within Functions
I have a function that selects a file to include, then includes is.
The file is including within the function, like so:

function include_file($file_name)
{
[lots of logic here to figure out the path...]
require $file_name;
return;
}

My problem is that the file gets included *within* the function, so
all the code in the file inherits the function's scope. Any variables
declared in the include file are not global -- they're local to that
function.

Is there any way around this? Is there anything I can put in the
included file or in the function to make sure that variables declared
within it are global? (I can't just reference the variables before
the require, because I have no way of knowing what's in the include
file.)

Required Files Confused Between Applications On Same Server
I'm running PHP 5.2.0 on my Windows XP laptop, running under IIS. I
have files named 'config.php' in two different web applications on
this machine, which are included throughout each via 'require' in one
and 'require_once' in the other.

When I attempt to use the two applications simultaneously, the file
which was 'require_once'-ed is also being accessed from the other
application, even though the two applications are isolated from each
other in IIS, and are in completely different directories on the
computer.

Include Files And Variable Scope
I'm having issues when including a file across an SSL connection, and the variable scope inside the include file. When including an include file from my HTTP domain, it seems to have problems using functions defined inside the include files on the HTTP domain, as well as unable to use variables defined from withing the HTTPS domain. Here's the setup I currently have:

I have a template file that is included on every page so that I can easily change out or update any of the includes. Example:

<?php

  $root = '/path/to/root/dir';

  $menu = $root.'/includes/menu.inc.php';
  $header = $root.'/includes/header.inc.php';
  $footer = $root.'/includes/footer.inc.php';

?>

Inside the include files, I may also include the root variable (to allow me to change easily from a local test server, to a web server) as such:
header.inc.php

<head>
  <style type="text/css" media="all">@import "<?php echo($root) ?>/css/stylesheet.css";</style>
</head>
<body>
  <img src="<?php echo($root) ?>/images/logo.png" />
...

This works great when I have everything on the same HTTP server, with no problems at all. Now the issue comes along where I also have a few pages which require SSL, which I have on their own HTTPS address. PHP is able to successfully include the files, AND output all the contents.

However, in the case above (header.inc.php) any variables defined outside the include files can not be found, giving $root a value of nothing. In addition, any functions defined inside the include files can not be found as well which makes my database connectivity unavailable.

I've attempted to change $root to define('ROOT', '/my/root/path') as well, and the same issue occurs.

My goal is ultimately to only have the pages when needed available via a HTTPS request, but any shared files available only on one server, so I don't have to update multiple files anytime a change is made. Am I missing something, or is what I'm attempting to accomplish just not possible?

Same Variables Used In 2 Included Files
I have 2 seperete files I am including into a script. They uses the same verriables however I want one to execute and then the other. will this be a problem?

No Error In Included Files
The problem is pretty simple.
If I include a file
<?
include 'libs.php'
?>

and this file contains an error (a missing ;),
my php installation does not tell me anything.
I simply receive no output.

Session Data In Included Files
How does a script access the variables in a session file?

Scenario:
<?-- this is the main script
include("main.inc.php")
$Username = $myname //myname is a variable in the session file
$html = new html; //html class defined in main.inc.php sneds out headers and so on
do lots of other php stuff
$html -> send_footer() // found in main.inc.php and itself 'includes' footer.php
?>

Now footer.php 'included' from within the function send_footer defined in main.inc.php and called by the primary script wants to access $myname, the session variable that stores my user name. i can't seem to get it at all. Has anyone any idea or am i being too vague here? Do I need to do something else at the beginning of footer.php that 'gets' the variable again from the session file? If so, how? The session ID is accessible to it cos I had it print it out to make sure, and the session file does definately hold a variable of the right name, I just can't return the data for some reason.

Passed Variables In Included Files
I'm looking for a guide on how variables are handled in included files. A pitfall I've run into is that if I define a variable, then include a file, the variable can be displayed on the included file. But if I try to call that same variables on the included page within a function, the variable is undefined. Example: PHP Code:

Sending Queries & Variables Across Included Files
I'm working on a template parsing engine of sorts. Basically the way it works is, depending on how a variable is set, a file is included. The file is an entire page containing HTML and PHP, starting at the <html> tag.

What I had planned on doing was writing a query for that specific type page. For instance, on "index.php" I have my connection script, and on "include.php" I have the while($row = mysql_fetch_array($query)) loop to actually display what results the query got.

Problem 1: Unless I write the query into a variable on include.php, I get an error. The error states that the query isn't a valid MySQL resource, but I know for certain it is, because if I write the exact same query on the included page with the exact same connection script, it works fine.

Problem 2: For files that are included off of the included page (for example, I have an include on include.php that links "homeslice.php" to the page), I have to use the full path (http://mysite.com/ect/homeslice.php) rather than just the site path, (/ect/homeslice.php).

My question: Is there a trick to getting these things to work the way I want them to, and if so, could someone please let me in on it?

MySQL Transactions Doesn't Work With Included Files?
I have a situation where I open a database connection in main script.
Then I start a transaction, have some queries, include an another php
file within some queries and then commiting queries in the main script.
All queries in the main script gets committed but those in the included
file doesn't. Why's that? Adding COMMIT query to the included file
doesn't work either. Here are an test code which clears what I mean:

the main file (test.php):
<?PHP
$db = mysql_connect ("localhost", "dbuser", "dbpass") or die ("Database
connection error!");
mysql_select_db("databasename") or die ("Database selection error!");

mysql_query("START TRANSACTION", $db);
mysql_query("INSERT INTO news VALUES (NOW(),'author','message from main
script')", $db);

include "test2.php";

mysql_query("COMMIT",$db);
mysql_close($db);
?>

and the included one (test2.php):
<?PHP
mysql_query("INSERT INTO news VALUES (NOW(),'author2','message from the
included script')", $db);
?>

So, this script runs fine, but there is just one row inserted to db (the
one from the main script (test.php)). var_dump of $db in the included
script tells as it should: resource(2) of type (mysql link)

Tables are InnoDB type and START TRANSACTION and COMMIT both returns
true (1). I also made some error handlers but those were not trapped either.

Session Variables Do Not Persist Into Included Files
In my index.php file I set a session variable

$_SESSION['product'] = "foo";

and then in my html part of index.php I include a file menu.php using require_once() which I use to build the menu tree. However, the session variable is not available to me inside that include file. It is available to me inside index.php because if I echo it I can see it. If I go to page2.php it is also there. Just not in the include file.

Files Not Being Included With Set_include_path() Or Ini_set('include_path')
I cannot seem to wrap my head around this peculiar problem. I have tried using both the function to set my include path, and then echo the get_included_files() and the files do not appear in the array. I can use require() or include() with no problems, but when I try to set the include path, the files do not seem to be included. Is there some weird quirck or gotcha to using this feature of PHP? I thought all you have to do is provide the directory and viola it should work. Any advice?

Classes Uncallable From Files Included Inside Functions.
I'm modifying a copy of oscommerce to work with a template system I'm building. This template system basically just includes a list of files in the order they are specified in the database and sets their permissions etc.

It includes the files through a function, which is limiting the included files from referencing objects/classes/anything. Code:

Problem With A File Included Twice When I Want It To Be Included Once
I have a problem with a file that apparently is being included twice when I want it to be included once. I searched all my files and couldn’t find a place in which I am not calling it with include_once("file_name")

Is there a way to print or output in any way which file calls this file?
It could be an included file that calls this file, so I need to know the file name, not the page name that calls this file.

Included File Not Included Every Time
I have some pages where I'm including a header for the document - beginning of the HTML, style sheet, javascript, logos etc.

The problem is that sometimes it's being included and sometimes it isn't - and I'm talking even on the same page. The header file is in the same folder as the document I'm including it in, so I'm just using: PHP Code:

Globals And Super Globals
I'm looking for the best way to deal with globals in PHP.

As a 'C' software developer, I would normally avoid all
globals and not have any at all, but use structs and pass
everything in the function parameters...

However, being realistic, I can see that globals can (and
do ?) have a place in PHP web scripts.

As I see it, there are two approaches:

1) go with globals,

2) avoid globals.

Looking at (1)
==============

Sure, I can just put a 'global $a' at the start of every
function that requires the use of the global '$a', but its
an easy mistake to forget this, and would not cause an error
('$a' will be read as NULL).

So, is there a way for a script to declare that a variable
should be a 'superglobal', just like $_SERVER is.

If not - could this be a useful addition to PHP ?

Looking at (2)
==============

If I put all my globals into an array/hashtable, eg.

$superglobal['a'] = 'hello world'

then this emulates the idea of a 'struct' in 'C', and I can
pass it through all my functions (or not bother with doing
that and use it as my one and only global).

Questions
=========

I prefer the idea of (2), but I wonder if its just going too
far ? Would anyone suggest what the prefered way of having and
using globals is ?

Could 'SUPERGLONAL' be added to PHP, to decalre a variable to be
superglobal ?

Confused About PHP!?
I am creating a site in FrontPage, and want to use PHP to validate a form I
have created, however I would like the return of the users input (which the
user reviews to check for errors), to be in the same design or style which
the rest of my site has been created in. I have found a script wich does the
basics of what I want, but it needs a lot of modifying, and I have a few
questions. Here is the script:

<?php
/* Program name: checkRegInfo.php
* Description: Program checks all the form fields for
* blank fields and incorrect format.
*/
?>
<html>
<head><title>Registration Validation</title></head>
<body>
<?php
/* set up array of field labels */
$label_array = array ( "first_name" ="First Name",
"middle_name" ="Middle Name",
"last_name" ="Last Name",
"phone" ="Phone");
foreach ($_POST as $field =$value)
{
/* check each field except middle name for blank fields */
if ( $value == "" )
{
if ($field != "middle_name")
{
$blank_array[$field] = "blank";
}
}
elseif ($field == "first_name" or $field == "middle_name"
or $field == "last_name" )
{
if (!ereg("^[A-Za-z' -]{1,50}$",$_POST[$field]) )
{
$bad_format[$field] = "bad";
}
}
elseif ($field == "phone")
{
if(!ereg("^[0-9)( -]{7,20}(([xX]|(ext)|(ex))?[ -]?[0-9]{1,7})?$",$value))
{
$bad_format[$field] = "bad";
}
}
}
/* if any fields were not okay, display error message and form */
if (@sizeof($blank_array) 0 or @sizeof($bad_format) 0)
{
if (@sizeof($blank_array) 0)
{
/* display message for missing information */
echo "<b>You didn't fill in one or more required fields. You must
enter:</b><br>";
/* display list of missing information */
foreach($blank_array as $field =$value)
{
echo "&nbsp;&nbsp;&nbsp;{$label_array[$field]}<br>";
}
}
if (@sizeof($bad_format) 0)
{
/* display message for bad information */
echo "<b>One or more fields have information that appears to be
incorrect. Correct the format for:</b><br>";
/* display list of bad information */
foreach($bad_format as $field =$value)
{
echo "&nbsp;&nbsp;&nbsp;{$label_array[$field]}<br>";
}
}
/* redisplay form */
$first_name = $_POST['first_name'];
$middle_name = $_POST['middle_name'];
$last_name = $_POST['last_name'];
$phone = $_POST['phone'];.......

Confused With Preg_match!
I am trying to search through a line of html for the pattern ">anything<", but cannot seem to figure out preg_match.

I have read examples here, and read the php docs, and am still having trouble understanding how to create a pattern that will work.

I was trying this but don't really understand what I am doing, sad to say.

Confused By Mysqli
yes, I am another of those evil, spurned, damnable
Perl mongers, but I'm not trying to start a flamewar, I'm juust tryung
to understand something...

I can write a script in Perl like so, and it's pretty to me (and the
using of the heredocs I think does defend perl against many arguments
withthe HTML being all escaped and explicit returns and stuff -- which
I can see... 'print "<p class="text">stuff</p>
";' is terrible to
me to.. so I use heredocs), and simple, and fast under mod_perl...

....but I don't want my horizons limited so I wan to work out how to do
it in PHP:

#!/usr/bin/perl
use strict;

use CGI;
use DBI;

sub notLoggedIn();

my $cgi = new CGI;
print $cgi->header;
my $sessionid = $cgi->cookie('session');

notLoggedIn unless $sessionid;
my $dbh = DBI->connect('DBI:mysql:session','user','password');

my $get_session_st = <<"EOF";
SELECT *
FROM session
WHERE id = ?
EOF
my $get_session = $dbh->prepare($get_session_st);
$get_session->execute($sessionid);

my $session;
$session = $get_session->fetchrow_hashref or notLoggedIn;
$get_session->finish;

for my $k (keys %{$session}) {
$ENV{"SESSION_".uc($k)} = $session->{$v};
}

print <<"EOF";
<!--#include virtual="/includes/page_header.shtml"-->
<p>You are logged in.</p>
<p>Here's your session data...</p>
<table>
EOF

while (my ($k, $v) = each %ENV) {
print <<"EOF" if $k =~ /^SESSION_/;
<tr>
<td>$k</td>
<td>$v</td>
</tr>
EOF
}

print <<"EOF";
</table>
<!--#include virtual="/includes/page_footer.shtml"-->
EOF

sub notLoggedIn () {
print <<"EOF" and exit;
<!--#include virtual="/includes/page_header.shtml"-->
<p>Sorry, you are not logged in.</p>
<!--#include virtual="/includes/page_footer.shtml"-->
EOF
}

this whole thing is pretty simple. But anyway...

Quote:

Confused About Frameworks
I have just started to look at frameworks and it is quite mind boggling. i have been to the official PEAR site and have installed it. but what do i do now? I mean how do i use it?

If i understand it correctly are framwork simply already written code that we can use?
could someone post a simple example of a simple script that uses any framework so i can get any idea. i have and will continue to search in the meantime but i just thought if someone could give me some example script it would atleast make me familiarise with it,

ALSO can we install more than one framework on a server or will it conflict as i am also thinking of installing ZOOP.

Scope "above" Session Scope?
I need help with storing a variable in some kinda of scope that's above session scope. I'm going to want every user to have access to this value, and it's going to be the same for all of them.

I Was Confused Between Isset() And Empty()
What's the diff between function isset() and empty()? I was totally confused.

I create a table with mysql as:

Confused With Exec() Parameter
i need help using exec(). this my first time to use it and kind of confused with all the examples that i see on the web and the PHP manual

all i need to do is to run a program call randgenerator.exe usually to run the program in DOS i will type. Code:

Confused On Load Balancing
I'm planning on putting together an application that will allow users to
upload many multi media files. But lets say my current provider limits
me to 300 gigs of HD space. I fully expect to fill that up, then I...

Confused By Unlink Problem!
I'm trying to delete a file.

unlink('../images/photos/1967_GT_500_Shelby_Mustang.jpg');
That works

$fm = "../images/photos/1967_GT_500_Shelby_Mustang.jpg";
unlink($fm);
That doesn't. Why?

I need to pass the file name as a variable as it's the result of a mysql
query.

Confused On PHP And Making A JDBC Connection
I have someone who has a proprietary database. They said that the only
way to access the DB is via a JDBC connection.

Now, does this mean I HAVE to use JAVA or JSP to connect to the DB? Does
PHP have the ability to make a connection using JDBC so that I can use
only PHP wo access the DB and use it in my web applications?

If the first thing that comes to your mind is "Ask the people who created
the DB"...I did, and they have no clue.

Confused: Casting A Variable To Integer
Maybe I should stop working because this seems soo basic.
I almost feel ashamed to ask, but here we go.
:-/

Consider the following script:

<?
$name="henk";

echo "$name=$name <br>";
echo "(int)$name=".(int)$name."<br>";

if ($name == (int)$name){
echo "equal";
} else {
echo "Not equal";
}
?>

produces:
-----------------
$name=henk
(int)$name=0
equal
------------------

What am I missing here?

Is PHP casting the string "henk" to 0 somehow?

Php 'if' Scope
is the variable - $TimeStamp (initiated in the first if statement) outside the scope of the second 'if' statement?

if so why and how do i go about accessing it?


if ($node->nodeName == "Date") {
$TimeStamp = trim($elem->nodeValue);
print '<div class="containerNewsItem"><div class="indexDate">'
convertTimeStamp($TimeStamp);
print '</div>'
}
if ($node->nodeName == "Title") {
print '<div class="indexTitle">' . '<a href="xnView.php?release=' . $TimeStamp . '">' . trim($elem->nodeValue). '</a></div></div>'
}

Constant Scope
I have a site where one page consists of several includes. The constant
HTTP_MAIN is contained in the constants.php file which is included in the
index.php file. A hdr.php file is included in the index.php file.

I cannot seem to access HTTP_MAIN from within the hdr.php file. Any ideas?
The index.php and the hdr.php reside under different domains (one is under a
secure folder).

Variable Scope?
I'm working with a while loop:

$i = "0";
$result = mysql_query("SELECT * FROM table",$db);
while ($myrow = mysql_fetch_array($result)) {
$current_id = array($i => $myrow["id"]);
echo"$current_id[$i]<br><br>";
$i++;
}

Which of course works fine. But when i try and somthing like echo"$current_id[3]"; out side of the while() loop nothing happens. Is this related to the $current_id array only being local to the while() loop and droped once the loop is done, or am i messing up somewhere else?

Session Scope
My session class has stopped working and I have no clue why. I
haven't touched the code in weeks. I have a session class (copied
from the book Professional PHP5) that returns an object of that class
and has an Impress() method that touches a database table and stores
session info.

At the beginning of each php file, I have these two lines:
$objSes = new MySessionClass();
$objSes->Impress();

As I said, this code was working perfectly and for weeks and hasn't
been modified. However, now every time I open a new php file and
execute the $objSes = new MySessionClass(), I'm apparently starting a
new session. It is not returning an object of the previous session
info. Of course, this is causing everything to crap out.

How can I create an $objSes instance which is visible globally to all
php files but not to other users of the application? Would the global
keyword do this or would that also make it visible to other users?

Static Scope
In server-side scripting, to whom are static members available? Since it's executing on the server, can one visitor get a static property value that was set by the actions of another?

PHP Static Scope
I'm kinda new to PHP and I'm running into something that just seems
odd. There's a good chance I'm just doing something wrong though. I'm
trying to implement a simple singleton:

private static $instance;
public static function Instance()
{
if (!isset(self::$instance))
{
self::$instance = new MyClass();
}
return self::$instance;
}

which pretty much follows the common pattern. I've noticed through,
either by using a var_dump on self::$instance or by simply outputting
"test" inside the IF statement, that my if statement always executes.
If I call Instance twice within the same request, the singleton works,
but if I refresh or open a new browser, each request seems to create
it's own version. Am I doing something wrong or are static's scoped to
thread requests? I would expect the block within the if to fire once
throughout the life of the application (or until php resets itself or
whatever).

I'm just messing with things on IIS - incase that could be the issue.

Variable Scope
I am a little surprised that the following that $x is visible outside of the
scope in
which it is (?)defined(?) (not sure if that is the correct term here). I am
trying
to find where in the php docs that this is discussed. Haven't found anything
yet.

I am also assuming that the following scoping rule holds for other
constructs
as well.

if(true)
{
$x= '_hello'
}

if(false)
{

}
else
{
$x= $x.'_world'
}

echo $x;

//output: _hello_world_

Scope Of A Function
My question is what is the scope of a function defined in a php file?
If I want to call a function I defined in another file, do I need to do something like include that PHP file in this new PHP file or will it be just accessible? Though personally I think we'll need to include it of course...

The problem in searching is that when I do search for this, I end up reading excerpts for function scope, i.e. scope of variables etc which are declared within a function, that's not what I am looking for, I want to know the scope of these declared functions...

I have programming knowledge as well as experience in c/c++/java/VB/VC++/C#/ASP/Advanced Java/.NET etc...hence i understand most of the concepts of OOP as well as general programming.

Classes And Variable Scope
I'm wondering is there any way I can get a variable's value from within a
class when the variable has been declared outside the class but in the same
script as the class is contained in. For example, say I have the following
script

<?php
constant myvar = "my original string";
class myClass
{
function returnmyvar()
{
return "some processed text and ".$myvar;
}
function usesnewstr()
{
echo $this->returnmyvar();
}
}
$myCls = &New myClass($myvar);
$myCls -> usesnewstr();
?>

Now what I'd like this to output would be:
some processed text and my original string
but all I get is:

some processed text and

Now I know I could make a constructor function and pass $myvar in that way
but I would rather not have to do that as that would entail changing the
instatiation statements whevever that class is already used. Any other ways
to make $myvar visible to functions inside the class?

Using Arrays In A Global Scope.
I'm having a bit of fun at the moment. I've written some php scripts that
I am using with MySQL. The results of quieries are coming back in an
array called 'row'. Now if an element (inxed) did not exist before I
upgraded it just returned a null, now it returns an error message.

To get round this I decided to check that the array index actually exists
before trying to display its contents:

function Echo_Field ( $field ) {
//global $row;

if ( isset($GLOBALS["row"][$field]) ) {
echo($GLOBALS["row"]["field"].",");
} else {
echo(",");
}
}

Eg if $row["wibble"] exists and is equal to "foobar" then

Echo_Field ("wibble);

would output "foobar,", if $row["wibble"] did not exist then "," would be
the result.

My assumption was that row would be in the global scope then the above
should echo it if it exists. It does not.

Classes And Variable Scope
can anyone explain why this errors with 'Call to a member function on a non-object' as it stands, but its ok in the constructor. I thought class level variables were accessible from anywhere in the class. PHP Code:

Variable Scope In PHP Classes
I am having some problems with variable scope in my php classes. I thought
varibles declared in classes were visble throughout the class, but I am
finding this is not the case.

What is happening is that when functions in my class go to access variables
they are returning nothing even though they have had values assigned..

Given A Variable Global Scope
Let's say I have a script like this:

<?php
$FOO = "important constant";
usefulfunction();
function usefulfunction() {
echo "The value of FOO is $FOO<p>n";
return;}?>

In that script, usefulfunction() won't print the value of FOO as specified in the main body of the script. Is there a way to give the variable $FOO global scope, so it could be used in functions?

I know that I could use define("FOO","a useful constant"), but sometimes it would be useful to use a variable. If there's no way to do this, I'll just use constants.

Variable Scope Issue
This is seriously blowing my mind.

$a = array('a', 'b', 'c');
for ($i=0; $i<=count($a); $i++) {
echo 'In FOR: '.$a[0].' - '.$a[1].' - '.$a[2]."
";
if ($a[$i] = 'a') {
echo 'In IF: '.$a[0].' - '.$a[1].' - '.$a[2]."
";
}
}

Ok, I expected the above to output:

In For: a - b - c
In IF: a - b - c
In For: a - b - c
In For: a - b - c

But I get this:

In For: a - b - c
In IF: a - -
In For: a - b - c
In For: a - b - c

Variable Scope Issue
I have a function foo () in a file called funcfoo.php called from my main
program file main.php, which has an include for that file.

Foo () contains a line:

echo $bar;

Now I have a (global) variable $bar which is set in main:

GLOBAL $bar;
$bar = 1;

When I call foo () from main it doesn't echo the value 1. (How) can I make
$bar visible to foo () without explicitly passing it as a parameter ? Is the
only way putting the entire foo function body in the same file as main ?

Database Connectivity Scope
I am wondering how to set up ONE DB connection once only which can be torn down on leaving a web site. Basically I want my DB connection to remain open across multiple pages without going through the process of setting up and tearing down a new connection for each and every page that will query a DB. I have tried this with '$global DB_connect_id' on one page but it is not visible in other pages ..

Are $_POST And $_GET Available In Global Scope?
I have a multi purpose page, let's say page1.php PHP Code:

Singleton Class Scope Problem
On my site I want to make two classes. One that can be instantiated
normally and one with extended functionality that can only be
instantiated once. The Singleton pattern thus seems like a logical
choice for the second class. However, I would like the second
(singleton) class to extend the first. Something like this:

<?php
class User
{
public function __construct ()
{
doSomething();
}
}

class Member extends User
{
private static $instance = NULL;
public static function getInstance ()
{
if (self::$instance === NULL)
self::$instance = new Member;
return self::$instance;
}

private function __construct () {}
private function __clone () {}
}
?>
But this gives me the following error:
Fatal error: Access level to Member::__construct() must be public (as
in class User) in class.member.php on line 6

But I don't want the constructor to be public, because I want it to be
impossible to create more than one instance.

Using PostgreSQL With PHP / Scope An Lifetime Of $result
The following PHP-Code

My question:

What's the scope and lifetime of the $query Resource ? Can I still use it
after calling pg_close ? or do i have to copy all my rows, fields and stuff
before calling pg_close.

Suppose I'd use the mentioned Code in a function wich will return $query as
a result. Will the return value of the function still be valid and usable?

How To Get All Variables Defined In The Current Scope?
e.g.

$a = 1;
$b = 2;

i want to get all the variables defined in the current scope, is it
possible?

Include In Subdomain And Variable Scope
There seems to be a problem using a variable's value in an included file when the main file is in a subdomain and the included file is in the main domain. PHP Code:

PHP Limitation: Static Inheritance And Scope
As many people have noticed by now, PHP exhibits some frustrating
behavior when it comes to static fields and methods. For instance,
when a static method is defined in a parent class, but called from a
child class, the method uses the parent class for scope (not the
originating child class). For example, see the following block of
code:

class Parent {
private static $className = 'Parent'

public static function getName() {
return self::$className . "
";
}
}

class Child extends Parent {
private static $className = 'Child'
}

echo Parent::getName();
echo Child::getName();

------------------------------
Intuitive Results
------------------------------
Parent
Child

------------------------------
Actual Results
------------------------------
Parent
Parent

Does anyone know if the PHP dev team has plans to remedy this issue? I
personally feel that the inability to handle static scoping with
inheritance is a major limitation to the OO functionality of PHP. I've
seen several relevant bug reports on bugs.php.net, but most have been
categorized as Bogus. One member of the dev team flat out insulted one
of the bug reporters, saying "Sorry, you have a complete wrong idea og
OO programming. [sic]"

http://bugs.php.net/bug.php?id=30140
http://bugs.php.net/bug.php?id=30423
http://bugs.php.net/bug.php?id=30934
http://bugs.php.net/bug.php?id=30235

However, reading through the various bug reports, I wonder if the dev
team may be softening just a bit in their resistance more recently. I
recommend voting for the bugs above, submitting more functionaity
requests, and continuing discussion in developer forums. Short of
fixing it ourselves, what else can we do to convince the PHP dev team
to address this problem?

Scope Problem Using Functions And Require_once
Below is a code snippet I am having a hard time with. I rerquire code1.php
and code 2.php.

code1.php contains some variables the code needs.
code2.php contains some functions I call from the function below,
look_at_data().

Line 4 "echo" below corrctly shows the var_name from code1.php. BUT, when I
call it again at the end of the snippet below, it shows nothing.

================================================== ======

require_once('../lk/code1.php');
require_once("code2.php");

echo "name = ".var_name;

if($HTTP_POST_VARS['Submit']=='submit'){
$error = look_at_data($_POST); //**********
if ($error == "") {
$success = "User inserted successfully";
}
}

function look_at_data($form23_data) { //**********
require_once('../lk/code1.php');
echo "name = ".var_name;
........


Copyright © 2005-08 www.BigResource.com, All rights reserved