Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #1838

Re: foreach in reverse

From Helmut Chang <usenet@helmutchang.at>
Newsgroups comp.lang.php
Subject Re: foreach in reverse
Date 2011-05-25 08:19 +0200
Organization A noiseless patient Spider
Message-ID <iri72o$k1o$1@dont-email.me> (permalink)
References <54289e0b-89c3-4bc5-9077-77a2568b66fe@q12g2000prb.googlegroups.com>

Show all headers | View raw


Am 25.05.2011 02:43, schrieb Evolution:

> Also, I read somewhere that session_register() and session_start() are
> depricated and should not be used.

You should always consult the manual first for such questions:

<http://www.php.net/manual/en/function.session-register.php>

It's indeed deprecated since 5.3. It's the very, very "old" and 
unsecure(?) way to register a variable in the session.

>  However, when removed them, some
> code seems to have stopped working.

Yes, because on the other hand, session_start() is not deprecated, but 
necessary to (aas the name indicates) start the session.

Again: consult the manual:

<http://www.php.net/manual/en/function.session-start.php>

> Below is an example of how I've
> been using session_register() and session_start().   What code would
> be proper here?
>
>     session_register();
>     session_start();
>     $html_title="UCSB Earth Science : Home";
>     $_SESSION['html_title'] = $html_title;

First: you should turn on error reporting. The above code should give at 
least one warning, because session_register() expects at least one 
parameter.

Second: trying to register a variable (what you don't in your usage of 
session_register(), because you don't pass the name of a variable to 
register) before you start the session...?

On the other hand, session_register() implicitly starts the session, if 
none has been started already. So the following call of session_start() 
would raise a notice, that the session already had been started.

And last: I wouldn't use the variable $html_title, if it's not needed 
elsewhere in the code. It'sjust a tiny issue. But in this way, you 
create a variable and in the next line, you create a copy of it in 
assigning it to the session, while the original variable is not used 
anymore.

So my opinion of a proper code here would be:

// Start the session:
session_start();

// Write data to the session:
$_SESSION['html_title'] = 'UCSB Earth Science : Home';

HTH, Helmut

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

foreach in reverse Evolution <cryptozoan@gmail.com> - 2011-05-24 17:43 -0700
  Re: foreach in reverse Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-24 21:40 -0400
    Re: foreach in reverse Evolution <cryptozoan@gmail.com> - 2011-05-24 22:11 -0700
      Re: foreach in reverse sheldonlg <sheldonlg@thevillages.net> - 2011-05-26 07:59 -0400
  Re: foreach in reverse Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-24 21:44 -0400
  Re: foreach in reverse "Peter H. Coffin" <hellsop@ninehells.com> - 2011-05-24 21:01 -0500
    Re: foreach in reverse Helmut Chang <usenet@helmutchang.at> - 2011-05-25 08:05 +0200
  Re: foreach in reverse Helmut Chang <usenet@helmutchang.at> - 2011-05-25 08:19 +0200
  Re: foreach in reverse Denis McMahon <denis.m.f.mcmahon@gmail.com> - 2011-05-25 15:07 +0000

csiph-web