php-general Digest 22 Dec 2007 07:47:11 -0000 Issue 5194

Topics (messages 266203 through 266222):

Re: Which file called the function?
        266203 by: Nathan Rixham
        266204 by: Cesar D. Rodas

I hate bugs...Mysqli issue
        266205 by: Jason Pruim
        266206 by: Zoltán Németh
        266208 by: Jason Pruim
        266209 by: Zoltán Németh
        266210 by: Jason Pruim
        266215 by: Colin Guthrie
        266220 by: Colin Guthrie
        266222 by: Zoltán Németh

Re: Opinion about the using $GLOBALS directly
        266207 by: Stut
        266216 by: Philip Thompson
        266218 by: Robert Cummings
        266219 by: Nathan Nobbe
        266221 by: Sancar Saran

Re: building PHP5.2.5 on Mac OS X Leopard (anyone know how to build a just an 
extension)
        266211 by: Jochem Maas
        266212 by: Daniel Brown
        266213 by: Daniel Brown

XML Parse Error
        266214 by: VamVan

Re: Just to confirm...
        266217 by: Michael McGlothlin

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
global.php
<?php
function myFunc($file) {
 echo $file;
}
?>

one.php
<?php
  include( 'global.php' );
  echo 'You are in file: ';
  myFunc($file = __FILE__);
?>

might work..

Christoph Boget wrote:
Let's say I have the following 3 files

global.php
<?
  function myFunc() { echo __FILE__; }
?>

one.php
<?
  include( 'global.php' );
  echo 'You are in file: ';
  myFunc();
?>

two.php
<?
  include( 'global.php' );
  echo 'You are in file: ';
  myFunc();
?>

In each case, what is echoed out for __FILE__ is global.php.  Apart from
analyzing the debug_backtrace array, is there any way that myFunc() would
display "one.php" and "two.php" respectively?

thnx,
Christoph


--- End Message ---
--- Begin Message ---
__FILE__ == "global.php"

On 20/12/2007, Christoph Boget <[EMAIL PROTECTED]> wrote:
>
> Let's say I have the following 3 files
>
> global.php
> <?
>   function myFunc() { echo __FILE__; }
> ?>
>
> one.php
> <?
>   include( 'global.php' );
>   echo 'You are in file: ';
>   myFunc();
> ?>
>
> two.php
> <?
>   include( 'global.php' );
>   echo 'You are in file: ';
>   myFunc();
> ?>
>
> In each case, what is echoed out for __FILE__ is global.php.  Apart from
> analyzing the debug_backtrace array, is there any way that myFunc() would
> display "one.php" and "two.php" respectively?
>
> thnx,
> Christoph
>



-- 
Best Regards

Cesar D. Rodas
http://www.cesarodas.com
http://www.thyphp.com
http://www.phpajax.org
Phone: +595-961-974165

--- End Message ---
--- Begin Message ---
Hi everyone.

I have a script that I've been using succesfully for quite awhile, and just today found a bug...

I attempted to insert a new record into the database and got this error in my error log:

[Fri Dec 21 11:08:43 2007] [error] PHP Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on line 31 [Fri Dec 21 11:08:43 2007] [error] PHP Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/ RAIDer/webserver/Documents/OLDB/add.php on line 33 [Fri Dec 21 11:08:43 2007] [error] PHP Warning: mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on line 35 [Fri Dec 21 11:08:43 2007] [error] PHP Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/ RAIDer/webserver/Documents/OLDB/add.php on line 41



And those lines from my script are:

//Create the statement
$stmt = mysqli_prepare($link, "INSERT INTO current VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); mysqli_stmt_bind_param($stmt, 'sssssssss', $FName, $LName, $Add1, $Add2, $City, $State, $Zip, $XCode, $Record);
//Add the record
mysqli_stmt_execute($stmt);

printf("%d Row Inserted.\n", mysqli_stmt_affected_rows($stmt));

// Redirect back to index.php for viewing
//header("Location: index.php");

//Close the statement
mysqli_stmt_close($stmt);



?>

The $stmt is line 30 only thing above it is mapping the post info to the field names to be inserted.

With my limited knowledge of mysqli functions, it could be the issue... But what I don't get is why this bug is rearring it's head now... When I'm supposed to go on vacation for a few weeks...

Any help would be greatly appreciated.

The basics of what I used was copied directly from the php.net site. so I'm very confused...




--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
2007. 12. 21, péntek keltezéssel 11.14-kor Jason Pruim ezt írta:
> Hi everyone.
> 
> I have a script that I've been using succesfully for quite awhile, and  
> just today found a bug...
> 
> I attempted to insert a new record into the database and got this  
> error in my error log:
> 
> [Fri Dec 21 11:08:43 2007] [error] PHP Warning:   
> mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt,  
> boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on  
> line 31
> [Fri Dec 21 11:08:43 2007] [error] PHP Warning:  mysqli_stmt_execute()  
> expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/ 
> RAIDer/webserver/Documents/OLDB/add.php on line 33
> [Fri Dec 21 11:08:43 2007] [error] PHP Warning:   
> mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt,  
> boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on  
> line 35
> [Fri Dec 21 11:08:43 2007] [error] PHP Warning:  mysqli_stmt_close()  
> expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/ 
> RAIDer/webserver/Documents/OLDB/add.php on line 41
> 
> 
> 
> And those lines from my script are:
> 
> //Create the statement
> $stmt = mysqli_prepare($link, "INSERT INTO current VALUES  
> (?, ?, ?, ?, ?, ?, ?, ?, ?)");
> mysqli_stmt_bind_param($stmt, 'sssssssss', $FName, $LName, $Add1,  
> $Add2, $City, $State, $Zip, $XCode, $Record);
> //Add the record
> mysqli_stmt_execute($stmt);
> 
> printf("%d Row Inserted.\n", mysqli_stmt_affected_rows($stmt));
> 
> // Redirect back to index.php for viewing
> //header("Location: index.php");
> 
> //Close the statement
> mysqli_stmt_close($stmt);
> 
> 
> 
> ?>
> 
> The $stmt is line 30 only thing above it is mapping the post info to  
> the field names to be inserted.
> 
> With my limited knowledge of mysqli functions, it could be the  
> issue... But what I don't get is why this bug is rearring it's head  
> now... When I'm supposed to go on vacation for a few weeks...
> 
> Any help would be greatly appreciated.
> 
> The basics of what I used was copied directly from the php.net site.  
> so I'm very confused...
> 
> 
> 

an error must have occurred with mysqli_prepare, so it returned a
boolean false, that's what all those warnings are complaining about...

are you sure $link is a valid mysqli link identifier?

greets
Zoltán Németh

> 
> --
> 
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424
> www.raoset.com
> [EMAIL PROTECTED]
> 

--- End Message ---
--- Begin Message ---

On Dec 21, 2007, at 11:22 AM, Zoltán Németh wrote:

2007. 12. 21, péntek keltezéssel 11.14-kor Jason Pruim ezt írta:
Hi everyone.

I have a script that I've been using succesfully for quite awhile, and
just today found a bug...

I attempted to insert a new record into the database and got this
error in my error log:

[Fri Dec 21 11:08:43 2007] [error] PHP Warning:
mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt,
boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on
line 31
[Fri Dec 21 11:08:43 2007] [error] PHP Warning: mysqli_stmt_execute()
expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/
RAIDer/webserver/Documents/OLDB/add.php on line 33
[Fri Dec 21 11:08:43 2007] [error] PHP Warning:
mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt,
boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on
line 35
[Fri Dec 21 11:08:43 2007] [error] PHP Warning:  mysqli_stmt_close()
expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/
RAIDer/webserver/Documents/OLDB/add.php on line 41



And those lines from my script are:

//Create the statement
$stmt = mysqli_prepare($link, "INSERT INTO current VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssssssss', $FName, $LName, $Add1,
$Add2, $City, $State, $Zip, $XCode, $Record);
//Add the record
mysqli_stmt_execute($stmt);

printf("%d Row Inserted.\n", mysqli_stmt_affected_rows($stmt));

// Redirect back to index.php for viewing
//header("Location: index.php");

//Close the statement
mysqli_stmt_close($stmt);



?>

The $stmt is line 30 only thing above it is mapping the post info to
the field names to be inserted.

With my limited knowledge of mysqli functions, it could be the
issue... But what I don't get is why this bug is rearring it's head
now... When I'm supposed to go on vacation for a few weeks...

Any help would be greatly appreciated.

The basics of what I used was copied directly from the php.net site.
so I'm very confused...




an error must have occurred with mysqli_prepare, so it returned a
boolean false, that's what all those warnings are complaining about...

are you sure $link is a valid mysqli link identifier?

greets
Zoltán Németh


Here is where I connect to the database:

<?php



$link = mysqli_connect($server, $username, $password, $database) ;

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}



?>
It looks valid to me... as long as it's connecting... the username/ password/database are all correct, I can log in from the command line with no issue....



--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]




--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
2007. 12. 21, péntek keltezéssel 11.50-kor Jason Pruim ezt írta:
> On Dec 21, 2007, at 11:22 AM, Zoltán Németh wrote:
> 
> > 2007. 12. 21, péntek keltezéssel 11.14-kor Jason Pruim ezt írta:
> >> Hi everyone.
> >>
> >> I have a script that I've been using succesfully for quite awhile,  
> >> and
> >> just today found a bug...
> >>
> >> I attempted to insert a new record into the database and got this
> >> error in my error log:
> >>
> >> [Fri Dec 21 11:08:43 2007] [error] PHP Warning:
> >> mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt,
> >> boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on
> >> line 31
> >> [Fri Dec 21 11:08:43 2007] [error] PHP Warning:   
> >> mysqli_stmt_execute()
> >> expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/
> >> RAIDer/webserver/Documents/OLDB/add.php on line 33
> >> [Fri Dec 21 11:08:43 2007] [error] PHP Warning:
> >> mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt,
> >> boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on
> >> line 35
> >> [Fri Dec 21 11:08:43 2007] [error] PHP Warning:  mysqli_stmt_close()
> >> expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/
> >> RAIDer/webserver/Documents/OLDB/add.php on line 41
> >>
> >>
> >>
> >> And those lines from my script are:
> >>
> >> //Create the statement
> >> $stmt = mysqli_prepare($link, "INSERT INTO current VALUES
> >> (?, ?, ?, ?, ?, ?, ?, ?, ?)");
> >> mysqli_stmt_bind_param($stmt, 'sssssssss', $FName, $LName, $Add1,
> >> $Add2, $City, $State, $Zip, $XCode, $Record);
> >> //Add the record
> >> mysqli_stmt_execute($stmt);
> >>
> >> printf("%d Row Inserted.\n", mysqli_stmt_affected_rows($stmt));
> >>
> >> // Redirect back to index.php for viewing
> >> //header("Location: index.php");
> >>
> >> //Close the statement
> >> mysqli_stmt_close($stmt);
> >>
> >>
> >>
> >> ?>
> >>
> >> The $stmt is line 30 only thing above it is mapping the post info to
> >> the field names to be inserted.
> >>
> >> With my limited knowledge of mysqli functions, it could be the
> >> issue... But what I don't get is why this bug is rearring it's head
> >> now... When I'm supposed to go on vacation for a few weeks...
> >>
> >> Any help would be greatly appreciated.
> >>
> >> The basics of what I used was copied directly from the php.net site.
> >> so I'm very confused...
> >>
> >>
> >>
> >
> > an error must have occurred with mysqli_prepare, so it returned a
> > boolean false, that's what all those warnings are complaining about...
> >
> > are you sure $link is a valid mysqli link identifier?
> >
> > greets
> > Zoltán Németh
> >
> 
> Here is where I connect to the database:
> 
> <?php
> 
> 
> 
> $link = mysqli_connect($server, $username, $password, $database) ;
> 
> /* check connection */
> if (mysqli_connect_errno()) {
>      printf("Connect failed: %s\n", mysqli_connect_error());
>      exit();
> }
> 
> 
> 
> ?>
> It looks valid to me... as long as it's connecting... the username/ 
> password/database are all correct, I can log in from the command line  
> with no issue....
> 

try a var_dump on $link and on $stmt after the mysqli_prepare and see
what it shows

greets
Zoltán Németh

> 
> >>
> >> --
> >>
> >> Jason Pruim
> >> Raoset Inc.
> >> Technology Manager
> >> MQC Specialist
> >> 3251 132nd ave
> >> Holland, MI, 49424
> >> www.raoset.com
> >> [EMAIL PROTECTED]
> >>
> >
> >
> 
> --
> 
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424
> www.raoset.com
> [EMAIL PROTECTED]
> 
> 

--- End Message ---
--- Begin Message ---

On Dec 21, 2007, at 12:01 PM, Zoltán Németh wrote:

2007. 12. 21, péntek keltezéssel 11.50-kor Jason Pruim ezt írta:
On Dec 21, 2007, at 11:22 AM, Zoltán Németh wrote:

2007. 12. 21, péntek keltezéssel 11.14-kor Jason Pruim ezt írta:
Hi everyone.

I have a script that I've been using succesfully for quite awhile,
and
just today found a bug...

I attempted to insert a new record into the database and got this
error in my error log:

[Fri Dec 21 11:08:43 2007] [error] PHP Warning:
mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt,
boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on
line 31
[Fri Dec 21 11:08:43 2007] [error] PHP Warning:
mysqli_stmt_execute()
expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/
RAIDer/webserver/Documents/OLDB/add.php on line 33
[Fri Dec 21 11:08:43 2007] [error] PHP Warning:
mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt,
boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on
line 35
[Fri Dec 21 11:08:43 2007] [error] PHP Warning: mysqli_stmt_close()
expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/
RAIDer/webserver/Documents/OLDB/add.php on line 41



And those lines from my script are:

//Create the statement
$stmt = mysqli_prepare($link, "INSERT INTO current VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssssssss', $FName, $LName, $Add1,
$Add2, $City, $State, $Zip, $XCode, $Record);
//Add the record
mysqli_stmt_execute($stmt);

printf("%d Row Inserted.\n", mysqli_stmt_affected_rows($stmt));

// Redirect back to index.php for viewing
//header("Location: index.php");

//Close the statement
mysqli_stmt_close($stmt);



?>

The $stmt is line 30 only thing above it is mapping the post info to
the field names to be inserted.

With my limited knowledge of mysqli functions, it could be the
issue... But what I don't get is why this bug is rearring it's head
now... When I'm supposed to go on vacation for a few weeks...

Any help would be greatly appreciated.

The basics of what I used was copied directly from the php.net site.
so I'm very confused...




an error must have occurred with mysqli_prepare, so it returned a
boolean false, that's what all those warnings are complaining about...

are you sure $link is a valid mysqli link identifier?

greets
Zoltán Németh


Here is where I connect to the database:

<?php



$link = mysqli_connect($server, $username, $password, $database) ;

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}



?>
It looks valid to me... as long as it's connecting... the username/
password/database are all correct, I can log in from the command line
with no issue....


try a var_dump on $link and on $stmt after the mysqli_prepare and see
what it shows

greets
Zoltán Németh

Hey Zoltan,

Thanks for looking, here's the result of the vardump, I did $link first and then $stmt

object(mysqli)#1 (0) { } bool(false)

Not quite what it should be is it?





--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]




--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]





--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Zoltán Németh wrote:
> an error must have occurred with mysqli_prepare, so it returned a
> boolean false, that's what all those warnings are complaining about...
> 
> are you sure $link is a valid mysqli link identifier?

And as a general rule, defensive programming approaches would state that
you should check all the return values before blindly using them.... in
fact that's not really defensive specifically, just GPP

Col.

--- End Message ---
--- Begin Message ---
Jason Pruim wrote:
> Thanks for looking, here's the result of the vardump, I did $link first
> and then $stmt
> 
> object(mysqli)#1 (0) { } bool(false)
> 
> Not quite what it should be is it?

Well the first bit looks fine but clearly the mysqli_prepare() is not
working properly.  Try calling mysqli_error() to see what the problem is.

Col

PS please try to strip more of the fluff from the quoted mails as it
makes it much quicker/easier to read the thread (context is good but we
don't need multiple copies of signatures etc. :)


--- End Message ---
--- Begin Message ---
2007. 12. 21, péntek keltezéssel 12.04-kor Jason Pruim ezt írta:

> Hey Zoltan,
> 
> Thanks for looking, here's the result of the vardump, I did $link  
> first and then $stmt
> 
> object(mysqli)#1 (0) { } bool(false)
> 
> Not quite what it should be is it?

surely not ;)
if this is the result for var_dump($link) then the connection fails. try
mysqli_connect_error() to see what is breaking.

greets
Zoltán Németh

> 
> >
> >
> >>
> >>>>
> >>>> --
> >>>>
> >>>> Jason Pruim
> >>>> Raoset Inc.
> >>>> Technology Manager
> >>>> MQC Specialist
> >>>> 3251 132nd ave
> >>>> Holland, MI, 49424
> >>>> www.raoset.com
> >>>> [EMAIL PROTECTED]
> >>>>
> >>>
> >>>
> >>
> >> --
> >>
> >> Jason Pruim
> >> Raoset Inc.
> >> Technology Manager
> >> MQC Specialist
> >> 3251 132nd ave
> >> Holland, MI, 49424
> >> www.raoset.com
> >> [EMAIL PROTECTED]
> >>
> >>
> >
> >
> 
> --
> 
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424
> www.raoset.com
> [EMAIL PROTECTED]
> 
> 

--- End Message ---
--- Begin Message ---
Richard Lynch wrote:
On Wed, December 19, 2007 11:22 am, Stut wrote:
well, if you have a long and complex function declaration which
begins
with global $whatever, and then all over the function $whatever is
used,
some dozens of lines later when looking for something in the code
you
might not have any idea that $whatever is global... however if you
used
$GLOBALS['whatever'] everywhere it would be trivial.
Indeed.

I don't really care how long the function is.

$connection is a global in the scripts.

It's the only global there is.

It's a global in any function that needs it.

If I can't remember that from day to day, then I need to find a nurse
to take care of me...

[shrug]

I feel sorry for anyone that ever inherits your code. You're making their life needlessly more difficult. I've inherited enough code in my time to appreciate the extra effort to create readable and maintainable code.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
On Dec 20, 2007, at 11:24 AM, Sancar Saran wrote:

Hello All,

Thanks for joining the conversation. It seems there where no real technical
dead end for using $GLOBALS directly.
Using $GLOBALS directly very similar to coding standarts. It just up to you.

Also I try explain my enviroment a liddle bit.

First of all my function declarationgs gonna like this

// Set Shorcut Variables
$arrConf   = &$GLOBALS['_LIVE']['_CONF'];
$arrStat   = &$GLOBALS['_LIVE']['_STAT'];
$arrDomSet = &$GLOBALS['_LIVE']['_DOMN'][$GLOBALS['_LIVE']['_STAT'] ['curDom']]
['settings'];
$arrLang   = &$GLOBALS['_LIVE']['_LANG'][$arrStat['language']];
$rootDir   = &$arrConf['rootDir'];
$webDir    = &$arrConf['webDir'];
$arrDb     = &$arrConf['_DB'];
$arrDbg    = &$GLOBALS['_LIVE']['_DEBG'];

Why are you using references to the $GLOBALS? If they're global, then there's only 1 instance/reference to it. Seems needless...


It grows and grows. And some times in small functions, function declarations
become larger than the function actual code.

Most of those GLOBALS usage are read only (like configuration variables, or
stored language keys) or need to update anywhere in the system.

And unde one condition it may become problem.

If 3rd party users develop some code under my enviroment and if there where some change about GLOBALS['name'] or PHP core developers may change GLOBALS to GLB (or someting like that) there may problem to update 3rd party code.

To prevent this, putting some variable translation functions for 3rd party
developers was good idea.

Other than this for my point of view it was very useful.

Thank you very much all of you.

Sancar


~Philip Thompson

"Personally, most of my web applications do not have to factor 13.7 billion years of space drift in to the calculations, so PHP's rand function has been great for me..." ~S. Johnson
--- End Message ---
--- Begin Message ---
On Fri, 2007-12-21 at 12:35 -0600, Philip Thompson wrote:
> On Dec 20, 2007, at 11:24 AM, Sancar Saran wrote:
> 
> > Hello All,
> >
> > Thanks for joining the conversation. It seems there where no real  
> > technical
> > dead end for using $GLOBALS directly.
> > Using $GLOBALS directly very similar to coding standarts. It just up  
> > to you.
> >
> > Also I try explain my enviroment a liddle bit.
> >
> > First of all my function declarationgs gonna like this
> >
> > // Set Shorcut Variables
> > $arrConf   = &$GLOBALS['_LIVE']['_CONF'];
> > $arrStat   = &$GLOBALS['_LIVE']['_STAT'];
> > $arrDomSet = &$GLOBALS['_LIVE']['_DOMN'][$GLOBALS['_LIVE']['_STAT'] 
> > ['curDom']]
> > ['settings'];
> > $arrLang   = &$GLOBALS['_LIVE']['_LANG'][$arrStat['language']];
> > $rootDir   = &$arrConf['rootDir'];
> > $webDir    = &$arrConf['webDir'];
> > $arrDb     = &$arrConf['_DB'];
> > $arrDbg    = &$GLOBALS['_LIVE']['_DEBG'];
> 
> Why are you using references to the $GLOBALS? If they're global, then  
> there's only 1 instance/reference to it. Seems needless...

Here's why:

<?php

$GLOBALS['myProject']['foo'] = 10;

function aFunction()
{
    $foo = $GLOBALS['myProject']['foo'];

    echo "Foo: $foo\n";
    $foo--;
}

function anotherFunction()
{
    $foo = $GLOBALS['myProject']['foo'];

    echo "Foo: $foo\n";
    $foo--;
}

aFunction();
anotherFunction();

print_r( $GLOBALS['myProject'] );

?>

When in fact, almost assuredly the following was desired:

<?php

$GLOBALS['myProject']['foo'] = 10;

function aFunction()
{
    $foo = &$GLOBALS['myProject']['foo'];

    echo "Foo: $foo\n";
    $foo--;
}

function anotherFunction()
{
    $foo = &$GLOBALS['myProject']['foo'];

    echo "Foo: $foo\n";
    $foo--;
}

aFunction();
anotherFunction();

print_r( $GLOBALS['myProject'] );

?>

Personally, I think $GLOBALS is a great location for project
configurations but I think it's necessary to use a second level for the
configuration and first level defines a space for your project. In this
way you're much less likely to run into variable clobbering issues. This
is why I used 'myProject' as the first level key in the above example.
Some purists out there will misguidedly say that nothing belongs in the
global space; however, they are wrong since function and class
definitions fall into global space and as such the solution is
equivalent to stuffing all your config vars into a class or function.
That said, I think use of the global space shouldn't be ad-hoc and
sloppy.

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---
--- Begin Message ---
On Dec 21, 2007 2:46 PM, Robert Cummings <[EMAIL PROTECTED]> wrote:

> On Fri, 2007-12-21 at 12:35 -0600, Philip Thompson wrote:
> > On Dec 20, 2007, at 11:24 AM, Sancar Saran wrote:
> >
> > > Hello All,
> > >
> > > Thanks for joining the conversation. It seems there where no real
> > > technical
> > > dead end for using $GLOBALS directly.
> > > Using $GLOBALS directly very similar to coding standarts. It just up
> > > to you.
> > >
> > > Also I try explain my enviroment a liddle bit.
> > >
> > > First of all my function declarationgs gonna like this
> > >
> > > // Set Shorcut Variables
> > > $arrConf   = &$GLOBALS['_LIVE']['_CONF'];
> > > $arrStat   = &$GLOBALS['_LIVE']['_STAT'];
> > > $arrDomSet = &$GLOBALS['_LIVE']['_DOMN'][$GLOBALS['_LIVE']['_STAT']
> > > ['curDom']]
> > > ['settings'];
> > > $arrLang   = &$GLOBALS['_LIVE']['_LANG'][$arrStat['language']];
> > > $rootDir   = &$arrConf['rootDir'];
> > > $webDir    = &$arrConf['webDir'];
> > > $arrDb     = &$arrConf['_DB'];
> > > $arrDbg    = &$GLOBALS['_LIVE']['_DEBG'];
> >
> > Why are you using references to the $GLOBALS? If they're global, then
> > there's only 1 instance/reference to it. Seems needless...
>
> Here's why:
>
> <?php
>
> $GLOBALS['myProject']['foo'] = 10;
>
> function aFunction()
> {
>    $foo = $GLOBALS['myProject']['foo'];
>
>    echo "Foo: $foo\n";
>    $foo--;
> }
>
> function anotherFunction()
> {
>    $foo = $GLOBALS['myProject']['foo'];
>
>    echo "Foo: $foo\n";
>    $foo--;
> }
>
> aFunction();
> anotherFunction();
>
> print_r( $GLOBALS['myProject'] );
>
> ?>
>
> When in fact, almost assuredly the following was desired:
>
> <?php
>
> $GLOBALS['myProject']['foo'] = 10;
>
> function aFunction()
> {
>    $foo = &$GLOBALS['myProject']['foo'];
>
>    echo "Foo: $foo\n";
>    $foo--;
> }
>
> function anotherFunction()
> {
>    $foo = &$GLOBALS['myProject']['foo'];
>
>    echo "Foo: $foo\n";
>    $foo--;
> }
>
> aFunction();
> anotherFunction();
>
> print_r( $GLOBALS['myProject'] );
>
> ?>
>
> Personally, I think $GLOBALS is a great location for project
> configurations but I think it's necessary to use a second level for the
> configuration and first level defines a space for your project. In this
> way you're much less likely to run into variable clobbering issues. This
> is why I used 'myProject' as the first level key in the above example.
> Some purists out there will misguidedly say that nothing belongs in the
> global space; however, they are wrong since function and class
> definitions fall into global space and as such the solution is
> equivalent to stuffing all your config vars into a class or function.
> That said, I think use of the global space shouldn't be ad-hoc and
> sloppy.


the global space does have good uses; i prefer to use it to cache on a
per-request
basis.  i think the global space can be easily abused however, as is the
case in
many projects ive encountered and unfortunately work on.
in many cases singleton is an excellent alternative, however, it add
complexity and
overhead, so sometimes globals are appropriate.

-nathan

--- End Message ---
--- Begin Message ---
example code
// current code

//--- Set DB
$GLOBALS['db'] = NewADOConnection($GLOBALS['c']['db']['type'].'://'. 
$GLOBALS['c']['db']['user'].':'.$GLOBALS['c']['db']['pass'].'@'.$GLOBALS['c']
['db']['host'].'/'.$GLOBALS['c']['db']['name']);
$ADODB_FETCH_MODE = ADODB_FETCH_NUM; // Fastest Get Method


function getGalaxy() {
$sqlGGal = "
SELECT *
  FROM ".$GLOBALS['c']['db']['pref']."universe
 WHERE planet_type     = 'planet'
   AND planet_galaxy   = '1'
   AND planet_owner_id = 'null'
 ORDER BY planet_id ASC";

$GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_ASSOC;
$resGGAL   = $GLOBALS['db']->Execute($sqlGGal);
return $resGal;
}

Other Suggestions

function getGalaxy() {
$dbPrefix = $GLOBALS['c']['db']['pref'];
$db = $GLOBALS['db'];
$sqlGGal = "
SELECT *
  FROM ".$dbPrefix."universe
 WHERE planet_type     = 'planet'
   AND planet_galaxy   = '1'
   AND planet_owner_id = 'null'
 ORDER BY planet_id ASC";

$GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_ASSOC;
$resGGAL   = $db->Execute($sqlGGal);
return $resGal;
}

or

function getGalaxy() {
$dbConfig = Zend_Registry::get('dbConfig');
$dbPrefix = $dbConfig['prefix'];
$db = NewADOConnection($dbConfig['type'].'://'. $dbConfig['user'].':'.
$dbConfig['pass'].'@'.$dbConfig['host'].'/'.$dbConfig['name']);

$sqlGGal = "
SELECT *
  FROM ".$dbPrefix."universe
 WHERE planet_type     = 'planet'
   AND planet_galaxy   = '1'
   AND planet_owner_id = 'null'
 ORDER BY planet_id ASC";

$GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_ASSOC;
$resGGAL   = $db->Execute($sqlGGal);
$db->Close();
return $resGal;
}

Etc etc. 

From my point of view first one was more usable. 

Anyhow dont worry. It seems PHP 5.3.0 supporting _NAMESPACE_ :)

Regards

Sancar

--- End Message ---
--- Begin Message ---
Daniel Brown schreef:
> On Dec 20, 2007 7:56 PM, Jochem Maas <[EMAIL PROTECTED]> wrote:
>> Frank Arensmeier schreef:
>>> How desperately are you trying
>>> to get thinks working?
>> desperate enough to move back to my windows machine ;-)
> 
>     For the love of God, Jochem, I will not sit idly by and allow that
> to happen.

trust I'll fight this until I win - there is no way I'm actually going to
go back to a windows machine fulltime (besides my mail is already on the mac
so there is no going back ;-))

> 
>     Is it possible that you can edit Makefile to compile just the
> Interbase extension after it's written by ./configure ?

maybe I could - I can at least get as far as opening the Makefile - but
to be honest I have never hacked one.

I'll get back to you as soon as I have had another stab at configuring/compiling
(right now I don't have any apache or php stuff lying around - I got annoyed and
confused so I rm -rf'ed the lot with the intention to try again from a clean 
slate.

happy holidays.

> 

--- End Message ---
--- Begin Message ---
On Dec 20, 2007 7:56 PM, Jochem Maas <[EMAIL PROTECTED]> wrote:
> Frank Arensmeier schreef:
> > How desperately are you trying
> > to get thinks working?
>
> desperate enough to move back to my windows machine ;-)

    For the love of God, Jochem, I will not sit idly by and allow that
to happen.

    Is it possible that you can edit Makefile to compile just the
Interbase extension after it's written by ./configure ?

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

--- End Message ---
--- Begin Message ---
On Dec 21, 2007 12:55 PM, Jochem Maas <[EMAIL PROTECTED]> wrote:
> I'll get back to you as soon as I have had another stab at 
> configuring/compiling
> (right now I don't have any apache or php stuff lying around - I got annoyed 
> and
> confused so I rm -rf'ed the lot with the intention to try again from a clean 
> slate.

    Remember, 'make clean' is your friend.  Then 'rm -f config.cache'
and you're good to go.

    Feel free to email your ./configure'd Makefile to me privately and
I'll have a look.  If all else fails, I'm willing to jump on the
server with you to help work it out.

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

--- End Message ---
--- Begin Message ---
Hi All,

Happy Christmas!!!

Please see the code below:


            $xml = "";
            $xml  = '<?xml version="1.0" encoding="UTF-8"?>';
            $xml .= '<request>';
            $xml .= '<emailAddress>'.
$this->xmlValueEncoding($post['Email']) .'</emailAddress>';
            $xml .= '<firstName>' .
$this->xmlValueEncoding($post['FirstName']) . '</firstName>';
            $xml .= '<lastName>' .
$this->xmlValueEncoding($post['LastName']) . '</lastName>';
            if (isset($post['Company']) && ($post['Company'] != ""))
                $xml .= '<company>' .
$this->xmlValueEncoding($post['Company']) .'</company>';
            if (isset($post['Title']) && ($post['Title'] != ""))
                $xml .= '<jobDesc>' .
$this->xmlValueEncoding($post['Title']) .'</jobDesc>';
            $xml .= '<password>' .
$this->xmlValueEncoding($post['Password']) . '</password>';
            if (isset($post['Address1']) && ($post['Address1'] != ""))
                $xml .= '<address1>' .
$this->xmlValueEncoding($post['Address1']) .'</address1>';
            if (isset($post['City']) && ($post['City'] != ""))
                $xml .= '<City>' . $this->xmlValueEncoding($post['City'])
.'</City>';
            if (isset($post['State']) && ($post['State'] != ""))
                $xml .= '<State>' . $this->xmlValueEncoding($post['State'])
.'</State>';
            if (isset($post['ZipCode']) && ($post['ZipCode'] != ""))
                $xml .= '<Zip>' . $this->xmlValueEncoding($post['ZipCode'])
.'</Zip>';
            if (isset($post['Country']) && ($post['Country'] != ""))
                $xml .= '<ISOCountryCode>' .
$this->xmlValueEncoding($post['Country']) . '</ISOCountryCode>';
            if (isset($post['Phone']) && ($post['Phone'] != ""))
                $xml .= '<Phone>' . $this->xmlValueEncoding($post['Phone'])
. '</Phone>';
            $xml .= '</request>';

function xmlValueEncoding($str) {

            return htmlspecialchars(trim($str), ENT_QUOTES, "UTF-8");

        }

I receive a XML parser errow when encoding the NON US Value like accent `
etc.

Can you please suggest me a solution?

I am using SOAP to send these values to a webservice.

Thanks,
Vamsee Vanaparthy

--- End Message ---
--- Begin Message --- I wish I could block IE users. They almost are more trouble than they are worth. Luckily only about 20% of my users still use IE6. :p
<?
    if(stristr($_SERVER['HTTP_USER_AGENT'],"msie")) {
        die("No friend of Internet Exploder is a friend of mine.");
    }
?>

Lol!!! I need to implement that on ALL my sites ... XD!!


Xavier de Lapeyre




-----Original Message-----
From: Richard Heyes [mailto:[EMAIL PROTECTED] Sent: jeudi 20 décembre 2007 14:26
To: Daniel Brown
Cc: Stut; [EMAIL PROTECTED]; Zoltán Németh; PHP General List
Subject: Re: [PHP] Just to confirm...

    Bah!  You're right, I changed it to just be an easter egg in the
code.  The original (now commented out) was:
<?
    if(stristr($_SERVER['HTTP_USER_AGENT'],"msie")) {
        die("No friend of Internet Exploder is a friend of mine.");
    }
?>

    It initially started to try to stop cURL, wget, Lynx, and other
automated clients from grabbing the content from the page.  Again, I
know that headers can be spoofed, but that's a different topic.  I try
to make a joke and Stut shoots me in the ass.  ;-P

I've got to ask, why on earth would you want to do this? Robots and things like wget I could understand more, but purposefully cutting out a large chunk of your audience?



--
Michael McGlothlin
Southwest Plumbing Supply

--- End Message ---

Reply via email to