php-general Digest 11 Mar 2012 23:11:18 -0000 Issue 7723

Topics (messages 316981 through 316988):

Re: questions about $_SERVER
        316981 by: Stuart Dallas
        316982 by: Daniel Brown
        316984 by: Tedd Sperling
        316986 by: Tim Streater

Re: Have little enough hair as it is ...
        316983 by: Lester Caine
        316988 by: Simon Schick

Re: Function mktime() documentation question
        316985 by: Tedd Sperling
        316987 by: Matijn Woudt

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On 11 Mar 2012, at 01:43, Tedd Sperling wrote:

> On Mar 10, 2012, at 3:53 PM, tamouse mailing lists wrote:
>> On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling <tedd.sperl...@gmail.com> 
>> wrote:
>>> That's correct, but to access those variables outside of their scope (such 
>>> as a function) you do via a SuperGlobal, namely $GLOBAL['whatever'].
>>> 
>>> As such, there are no "globals" in PHP other than SuperGlobals. As I said, 
>>> if I'm wrong, please show me otherwise.
>> 
>> I guess I don't know what you mean by "globals". I know what globals
>> are, but not "globals".
> 
> I don't understand your question. I know what questions are, but not your 
> question. :-)

I think the confusion is arising because the word superglobal is used in PHP 
when referring to globals, because the word global has been incorrectly applied 
for quite some time.

A global variable is a variable that is accessible in every scope, so Tedd is 
right… the only true globals in PHP are the superglobals. Here's an overview of 
the various scopes in PHP (I've probably missed some, but it's enough to make 
the point)…

<?php
  // Only visible when not in a function or class. The PHP manual calls
  // this the "global" scope: http://php.net/variables.scope
  $var1 = 'a';

  function funcB()
  {
    // Only visible inside this function.
    $var2 = 'b';
  }

  function funcB()
  {
    // This statement makes the variable from the top-level scope visible
    // within this function. Essentially this is the same as passing the
    // variable in to the function by reference.
    global $var1;
  }

  class classC
  {
    // Visible to methods in this class only.
    private $var3 = 'c';

    // Visible to methods in this class and methods in derived classes.
    protected $var4 = 'd';

    // Method visible in this class only.
    private methodA()
    {
      // Visible only inside this method.
      $var5 = 'e';
    }

    // Method visible in this class and methods in derived classes.
    protected methodB()
    {
      // See funcB()
      global $var1;
    }

    // Method visible on any instance of this class.
    public methodC()
    {
      // See funcB()
      global $var1;
    }
  }
?>

The global keyword allows you to expose a variable that has been defined at the 
top-level scope ($var1 in the above example) in the current scope. It does NOT 
create a global variable; the keyword is not an accurate reflection of what it 
does.

My guess is that calling the top-level scope "global" made sense when functions 
were the only other level of scope that existed. Now that we have yet more 
levels of scope it can be a bit confusing.

I hope this helps clear things up.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
On Sat, Mar 10, 2012 at 10:37, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
> As such, there are no "globals" in PHP other than SuperGlobals. As I said, if 
> I'm wrong, please show me otherwise.

    A superglobal is predefined at run-time by the parser,
environment, SAPI, etc. (_SERVER, _POST, _GET, _REQUEST, _ENV,
_SESSION, _COOKIE), whereas a global can be defined at any time, and
is available to the current instance.  All superglobals are globals,
but not all globals are superglobals.

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
On Mar 11, 2012, at 10:25 AM, Daniel Brown wrote:

> On Sat, Mar 10, 2012 at 10:37, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
>> As such, there are no "globals" in PHP other than SuperGlobals. As I said, 
>> if I'm wrong, please show me otherwise.
> 
>    A superglobal is predefined at run-time by the parser,
> environment, SAPI, etc. (_SERVER, _POST, _GET, _REQUEST, _ENV,
> _SESSION, _COOKIE), whereas a global can be defined at any time, and
> is available to the current instance.  All superglobals are globals,
> but not all globals are superglobals.
> 
> -- 
> </Daniel P. Brown>
> Network Infrastructure Manager
> http://www.php.net/


Now I'm confused.

My understanding is that all variables defined within the main script are 
accessible within the main script because they are all within scope by 
definition.

Additionally, main script variables are not accessible out of scope (such as in 
a function) unless one uses $GLOBALS to retrieve those values.

That is the limit of my understanding of $GLOBALS.

As to placing an additional requirement (i.e., being predefined) on the 
definition as to what constitutes a SuperGlobal is outside my understanding. As 
such, I must defer to the PHP Manual, namely:

http://php.net/manual/en/language.variables.superglobals.php

This document clearly states that $GLOBALS is a SuperGlobal -- what am I not 
understanding here?

Cheers,

tedd

_____________________
tedd.sperl...@gmail.com
http://sperling.com





--- End Message ---
--- Begin Message ---
On 11 Mar 2012 at 18:16, Tedd Sperling <tedd.sperl...@gmail.com> wrote: 

> On Mar 11, 2012, at 10:25 AM, Daniel Brown wrote:
>
>> On Sat, Mar 10, 2012 at 10:37, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
>>> As such, there are no "globals" in PHP other than SuperGlobals. As I said,
>>> if I'm wrong, please show me otherwise.
>>
>>    A superglobal is predefined at run-time by the parser,
>> environment, SAPI, etc. (_SERVER, _POST, _GET, _REQUEST, _ENV,
>> _SESSION, _COOKIE), whereas a global can be defined at any time, and
>> is available to the current instance.  All superglobals are globals,
>> but not all globals are superglobals.


> Now I'm confused.
>
> My understanding is that all variables defined within the main script are
> accessible within the main script because they are all within scope by
> definition.
>
> Additionally, main script variables are not accessible out of scope (such as
> in a function) unless one uses $GLOBALS to retrieve those values.

In the following, $x is a global but not a super-global (AFAIK).


<?php

function echox ()
     {

     global $x;

     echo $x;

     }

$x = "Hello world\n";

echox ();

?>

--
Cheers  --  Tim

--- End Message ---
--- Begin Message --- ( Been down London over night ;) ) ... and was not awake enough to change email address ...

http://piwik.medw.org.uk/phpinfo.php has http://piwik.medw.org.uk/ working
fine...

http://piwik.rainbowdigitalmedia.org.uk/phpinfo.php is just giving seg
faults on http://piwik.rainbowdigitalmedia.org.uk/ but
http://rainbowdigitalmedia.org.uk/ is working perfectly.

The piwik analytics is based on Zend, and I've not been able to get it
working on either of the two new machines, while all of my other stuff is
working fine. I started with Apache2.4.1 and PHP5.4.0 and moved back to what
should be the same versions as the working machines but without success.

Simon Schick wrote:
Can you give us some more information?
I've been working on this for some days and tried various combinations of Apache and PHP, but my starting point was Ap2.4.1 with PHP5.4.0 and I've now worked my way back through versions to what should be the same as setup as is working on piwik.medw.org.uk but I have yet to get piwik to run on either new machine!

How is php called in your apache-configuration? (f)cgi, module or somehow else?
You said that the configuration should be the same ... can you
double-check that? Reload the services etc ...
Always used module and I see no reason to change
I've enabled and disable just about everything, and the installer tells me the set-up is fine.

What about the logs? There must be more info in there ...
THAT is what is pissing me off. ZEND does not seem to log anything usable and I have yet to establish the best way of debugging it. The rest of my stuff simply worked, gave the expected new nagging and allowed me to track and tidy them. EVERY configuration of ZEND based piwik just gives ...
[notice] child pid 10345 exit signal Segmentation fault (11)
With eaccelerator switched on and tracking, I can see files being cached, but have yet to work out what the next file would be, and to be honest, I'm not convinced it runs the same way every time, but that is probably just the order of parallel paths being run?

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--- End Message ---
--- Begin Message ---
2012/3/11 Lester Caine <les...@lsces.co.uk>:
> ( Been down London over night ;) ) ... and was not awake enough to change
> email address ...
>
>
>> http://piwik.medw.org.uk/phpinfo.php has http://piwik.medw.org.uk/ working
>> fine...
>>
>> http://piwik.rainbowdigitalmedia.org.uk/phpinfo.php is just giving seg
>> faults on http://piwik.rainbowdigitalmedia.org.uk/ but
>> http://rainbowdigitalmedia.org.uk/ is working perfectly.
>>
>> The piwik analytics is based on Zend, and I've not been able to get it
>> working on either of the two new machines, while all of my other stuff is
>> working fine. I started with Apache2.4.1 and PHP5.4.0 and moved back to
>> what
>> should be the same versions as the working machines but without success.
>
>
> Simon Schick wrote:
>>
>> Can you give us some more information?
>
> I've been working on this for some days and tried various combinations of
> Apache and PHP, but my starting point was Ap2.4.1 with PHP5.4.0 and I've now
> worked my way back through versions to what should be the same as setup as
> is working on piwik.medw.org.uk but I have yet to get piwik to run on either
> new machine!
>
>> How is php called in your apache-configuration? (f)cgi, module or somehow
>> else?
>> You said that the configuration should be the same ... can you
>> double-check that? Reload the services etc ...
>
> Always used module and I see no reason to change
> I've enabled and disable just about everything, and the installer tells me
> the set-up is fine.
>
>> What about the logs? There must be more info in there ...
>
> THAT is what is pissing me off. ZEND does not seem to log anything usable
> and I have yet to establish the best way of debugging it. The rest of my
> stuff simply worked, gave the expected new nagging and allowed me to track
> and tidy them. EVERY configuration of ZEND based piwik just gives ...
> [notice] child pid 10345 exit signal Segmentation fault (11)
> With eaccelerator switched on and tracking, I can see files being cached,
> but have yet to work out what the next file would be, and to be honest, I'm
> not convinced it runs the same way every time, but that is probably just the
> order of parallel paths being run?
>
> --
> Lester Caine - G8HFL
> -----------------------------
> Contact - http://lsces.co.uk/wiki/?page=contact
> L.S.Caine Electronic Services - http://lsces.co.uk
> EnquirySolve - http://enquirysolve.com/
> Model Engineers Digital Workshop - http://medw.co.uk//
> Firebird - http://www.firebirdsql.org/index.php
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Hi, Lester

You're talking about some kind of "installer" ... What exactly is it?
And what exactly do you mean with "ZEND does not seem to log ..."?
Apache, PHP or something that's controlling both?
And the more interesting question as you're only talking about ZEND
... in which log-file have you found the notice? I guess it's the
log-file of Apache ...
I guess you have already tried to set Apache and PHP to the lowest
possible error-level ...

I searched up the inet and came across totally different solutions ...

Things that I found you can try:
* Replace the index.php ... Some people reported that this error was
caused by an endless-loop in their php-script
* Disable all php-modules that are not really needed (f.e. APC or eAccelerator)
* Disable all superfluous apache-modules (you should have done that
anyways, but let's try to put it to a minimum)

Here's also one tutorial how to get more information out of the
apache-process. Haven't tried that and can therefore just give the
hint to test it once.
http://stackoverflow.com/questions/7745578/notice-child-pid-3580-exit-signal-segmentation-fault-11-in-apache-error-l

Hope you can get some more details ...

Bye
Simon

--- End Message ---
--- Begin Message ---
On Mar 11, 2012, at 6:12 AM, Ashley Sheridan wrote:
> 
> I still don't see what's wrong with
> 
> date("t");
> 
> -- 
> Thanks,
> Ash

Ash:

It's just too damn simple -- we need to make things complicated. :-)

Actually, this works for me:

$days_in_month = date('t', mktime(0, 0, 0, $next_month, 0, $year));

But again, I don't see why I have to use "next month" to find the number of 
days in this month.

O', the mysteries of life.

Cheers,

tedd

_____________________
tedd.sperl...@gmail.com
http://sperling.com






--- End Message ---
--- Begin Message ---
On Sun, Mar 11, 2012 at 7:33 PM, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
> On Mar 11, 2012, at 6:12 AM, Ashley Sheridan wrote:
>>
>> I still don't see what's wrong with
>>
>> date("t");
>>
>> --
>> Thanks,
>> Ash
>
> Ash:
>
> It's just too damn simple -- we need to make things complicated. :-)
>
> Actually, this works for me:
>
> $days_in_month = date('t', mktime(0, 0, 0, $next_month, 0, $year));
>
> But again, I don't see why I have to use "next month" to find the number of 
> days in this month.

That's because you're requesting day 0 of some month, which refers to
the last day in the previous month.
Try: $days_in_month = date('t', mktime(0, 0, 0, $next_month, 1, $year));

- Matijn

--- End Message ---

Reply via email to