php-general Digest 13 Jan 2012 15:38:11 -0000 Issue 7648

Topics (messages 316279 through 316286):

Re: advise on simplfying session usage
        316279 by: Jim Giner
        316280 by: tamouse mailing lists
        316281 by: Haluk Karamete
        316282 by: tamouse mailing lists
        316283 by: tamouse mailing lists
        316284 by: mail.pmpa
        316285 by: David Courtin

Re: passing variables to php script
        316286 by: Tim Streater

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 ---
You're kidding us aren't you?

session("age") =90 versus $_SESSION['age']=90 (btw you left out a keystroke)
That's a difference of 2 keystrokes.  And you're looking to save keystrokes? 



--- End Message ---
--- Begin Message ---
On Thu, Jan 12, 2012 at 7:16 PM, Haluk Karamete <halukkaram...@gmail.com> wrote:
> Again, coming from ASP background, I'm trying to minimize the typing
> for most needed functionalities..
>
> in asp, to set a session var, you go <%session("age")=90%> and to
> output it, you just go <%=session("age")%>
>
> in php, you've got to _SESSION['age']=90. that's a lot of keyboarding,
> lots of double key strokes and the entire word session has to be
> uppercase.

if you haven't (yet) disabled caps-lock, this is one thing it's
typically used for -- successful strings of capital letters.

Anyway, if you use $_SESSION[] a lot, then creating a short 2-char
function can be helpful. Someone else coming along later to maintain
your code might be highly mystified about it though.

> of course, if you use an IDE and you get fast at it, this may not be
> an issue but I wanted to simplify it anyway.
>
> so the plan is this
>
> <?php
>
> _s("age",43) //set the session var age to 43
> echo _s("age") //outputs the value
>
> ?>
>
> To achieve this; I wrote this preliminary function;
>
> function _s($var,$val = "r4r53d323,9e809023890j832e@14fdsffdd")
> {
>        if ($val == "r4r53d323,9e809023890j832e@14fdsffdd")
>        {return $_SESSION[$var];}
>        else
>        {$_SESSION[$var] = $val;}
> }

You should add in a check to make sure the $_SESSION[$var] actually
exists as an index in your first return statement and return a value
you can check against for success/failure.

>
> Now, what's that number you ask!... it's just a value which I figured
> I would never end up in a real app.
> It's just a way for me to use default argument of the function so I
> can call _s function with 1 or 2 arguments.
>
> Can this be done a better way? How do you use _s function with 1 or 2
> arguments so in 1 arg mode, you can use it as a set, and in 2 arg
> mode, you use it as a way to return val.
>
> Is func_get_args route the only way? performance wise which one would better?

This would be the safest way in this case. I'm not 100% how this would
devolve into byte-code, but my assumption is that there would be a
very slight performance cost, however, since you are calling a
function for every access to the $_SESSION array, you've already bit
the majority of that cost.

> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

All in all, I would not use this sort of aliasing of a function to an
array to save typing. Get an IDE if it really is that onerous. I can
type ses<tab> and it expands to $_SESSION['index'] automatically
dropping me at the first apostrophe with the whole inner string
highlighted. Saves *LOTS* of typing.

--- End Message ---
--- Begin Message ---
I agree... that was just a wild idea! :)
Let's forget about it!

What's a good PHP programming editor you'd recommend on a mac for starters?




On Thu, Jan 12, 2012 at 6:39 PM, tamouse mailing lists
<tamouse.li...@gmail.com> wrote:
> On Thu, Jan 12, 2012 at 7:16 PM, Haluk Karamete <halukkaram...@gmail.com> 
> wrote:
>> Again, coming from ASP background, I'm trying to minimize the typing
>> for most needed functionalities..
>>
>> in asp, to set a session var, you go <%session("age")=90%> and to
>> output it, you just go <%=session("age")%>
>>
>> in php, you've got to _SESSION['age']=90. that's a lot of keyboarding,
>> lots of double key strokes and the entire word session has to be
>> uppercase.
>
> if you haven't (yet) disabled caps-lock, this is one thing it's
> typically used for -- successful strings of capital letters.
>
> Anyway, if you use $_SESSION[] a lot, then creating a short 2-char
> function can be helpful. Someone else coming along later to maintain
> your code might be highly mystified about it though.
>
>> of course, if you use an IDE and you get fast at it, this may not be
>> an issue but I wanted to simplify it anyway.
>>
>> so the plan is this
>>
>> <?php
>>
>> _s("age",43) //set the session var age to 43
>> echo _s("age") //outputs the value
>>
>> ?>
>>
>> To achieve this; I wrote this preliminary function;
>>
>> function _s($var,$val = "r4r53d323,9e809023890j832e@14fdsffdd")
>> {
>>        if ($val == "r4r53d323,9e809023890j832e@14fdsffdd")
>>        {return $_SESSION[$var];}
>>        else
>>        {$_SESSION[$var] = $val;}
>> }
>
> You should add in a check to make sure the $_SESSION[$var] actually
> exists as an index in your first return statement and return a value
> you can check against for success/failure.
>
>>
>> Now, what's that number you ask!... it's just a value which I figured
>> I would never end up in a real app.
>> It's just a way for me to use default argument of the function so I
>> can call _s function with 1 or 2 arguments.
>>
>> Can this be done a better way? How do you use _s function with 1 or 2
>> arguments so in 1 arg mode, you can use it as a set, and in 2 arg
>> mode, you use it as a way to return val.
>>
>> Is func_get_args route the only way? performance wise which one would better?
>
> This would be the safest way in this case. I'm not 100% how this would
> devolve into byte-code, but my assumption is that there would be a
> very slight performance cost, however, since you are calling a
> function for every access to the $_SESSION array, you've already bit
> the majority of that cost.
>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
> All in all, I would not use this sort of aliasing of a function to an
> array to save typing. Get an IDE if it really is that onerous. I can
> type ses<tab> and it expands to $_SESSION['index'] automatically
> dropping me at the first apostrophe with the whole inner string
> highlighted. Saves *LOTS* of typing.

--- End Message ---
--- Begin Message ---
On Thu, Jan 12, 2012 at 8:45 PM, Haluk Karamete <halukkaram...@gmail.com> wrote:
> I agree... that was just a wild idea! :)
> Let's forget about it!
>
> What's a good PHP programming editor you'd recommend on a mac for starters?

(Remember to bottom post.)

My favourite on the Mac is TextMate, but it's not $free. (It's also
not expensive and just in terms of time it can save, I'd say my $40
investment has been paid for many many times over). I also use Emacs
with a few extra packages, notably YASnippet.el, with a whole raft of
snippets converted from TextMate snippets, along with other pretty
standard Emacs accelerators. I am using Emacs more than TextMate these
days as my primary dev environment has shifted from OSX to GNU/Linux.

--- End Message ---
--- Begin Message ---
On Thu, Jan 12, 2012 at 8:52 PM, tamouse mailing lists
<tamouse.li...@gmail.com> wrote:
> On Thu, Jan 12, 2012 at 8:45 PM, Haluk Karamete <halukkaram...@gmail.com> 
> wrote:
>> I agree... that was just a wild idea! :)
>> Let's forget about it!
>>
>> What's a good PHP programming editor you'd recommend on a mac for starters?
>
> (Remember to bottom post.)
>
> My favourite on the Mac is TextMate, but it's not $free. (It's also
> not expensive and just in terms of time it can save, I'd say my $40
> investment has been paid for many many times over). I also use Emacs
> with a few extra packages, notably YASnippet.el, with a whole raft of
> snippets converted from TextMate snippets, along with other pretty
> standard Emacs accelerators. I am using Emacs more than TextMate these
> days as my primary dev environment has shifted from OSX to GNU/Linux.

I want to P.S. my comment with this: You are coming from ASP to PHP.
While the languages share a lot of similar conceptual and solution
space, they don't really share that much either syntactically or
semantically beyond a few basic things. Learning to use a new language
well is really all about learning the idioms of that language, well
beyond just the syntactic elements. PHP has lots of ways to accomplish
the same thing (almost like Perl in that way...) and it really pays to
explore the rich, rich library available.

--- End Message ---
--- Begin Message ---
When I have many calls to $_SESSION I do:

$s = &$_SESSION;
$s['foo'] = 'bar';

echo $s['foo'];  //bar

-----Original Message-----
From: Haluk Karamete [mailto:halukkaram...@gmail.com] 
Sent: sexta-feira, 13 de Janeiro de 2012 01:17
To: php-gene...@lists.php.net
Subject: [PHP] advise on simplfying session usage

Again, coming from ASP background, I'm trying to minimize the typing for
most needed functionalities..

in asp, to set a session var, you go <%session("age")=90%> and to output it,
you just go <%=session("age")%>

in php, you've got to _SESSION['age']=90. that's a lot of keyboarding, lots
of double key strokes and the entire word session has to be uppercase.
of course, if you use an IDE and you get fast at it, this may not be an
issue but I wanted to simplify it anyway.

so the plan is this

<?php

_s("age",43) //set the session var age to 43 echo _s("age") //outputs the
value

?>

To achieve this; I wrote this preliminary function;

function _s($var,$val = "r4r53d323,9e809023890j832e@14fdsffdd")
{
        if ($val == "r4r53d323,9e809023890j832e@14fdsffdd")
        {return $_SESSION[$var];}
        else
        {$_SESSION[$var] = $val;}
}

Now, what's that number you ask!... it's just a value which I figured I
would never end up in a real app.
It's just a way for me to use default argument of the function so I can call
_s function with 1 or 2 arguments.

Can this be done a better way? How do you use _s function with 1 or 2
arguments so in 1 arg mode, you can use it as a set, and in 2 arg mode, you
use it as a way to return val.

Is func_get_args route the only way? performance wise which one would
better?




--- End Message ---
--- Begin Message ---
In a session context with a lot of session vars, you can use magic methods 
__set and __get :

class s{
        private function __set($property, $value){
                $_SESSION[$property] = $value ;
        }

        private function __get($property){
                return $_SESSION[$property] ;
        }
}

and work with session like an object with the same access :

$s->one = 'one';
$s->oneTwo = array('one', 'two');

echo $s->one;

var_dump($s->oneTwo);

Le 13 janv. 2012 à 04:53, mail.pmpa a écrit :

> When I have many calls to $_SESSION I do:
> 
> $s = &$_SESSION;
> $s['foo'] = 'bar';
> 
> echo $s['foo'];  //bar
> 
> -----Original Message-----
> From: Haluk Karamete [mailto:halukkaram...@gmail.com] 
> Sent: sexta-feira, 13 de Janeiro de 2012 01:17
> To: php-gene...@lists.php.net
> Subject: [PHP] advise on simplfying session usage
> 
> Again, coming from ASP background, I'm trying to minimize the typing for
> most needed functionalities..
> 
> in asp, to set a session var, you go <%session("age")=90%> and to output it,
> you just go <%=session("age")%>
> 
> in php, you've got to _SESSION['age']=90. that's a lot of keyboarding, lots
> of double key strokes and the entire word session has to be uppercase.
> of course, if you use an IDE and you get fast at it, this may not be an
> issue but I wanted to simplify it anyway.
> 
> so the plan is this
> 
> <?php
> 
> _s("age",43) //set the session var age to 43 echo _s("age") //outputs the
> value
> 
> ?>
> 
> To achieve this; I wrote this preliminary function;
> 
> function _s($var,$val = "r4r53d323,9e809023890j832e@14fdsffdd")
> {
>       if ($val == "r4r53d323,9e809023890j832e@14fdsffdd")
>       {return $_SESSION[$var];}
>       else
>       {$_SESSION[$var] = $val;}
> }
> 
> Now, what's that number you ask!... it's just a value which I figured I
> would never end up in a real app.
> It's just a way for me to use default argument of the function so I can call
> _s function with 1 or 2 arguments.
> 
> Can this be done a better way? How do you use _s function with 1 or 2
> arguments so in 1 arg mode, you can use it as a set, and in 2 arg mode, you
> use it as a way to return val.
> 
> Is func_get_args route the only way? performance wise which one would
> better?
> 
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


--- End Message ---
--- Begin Message ---
On 13 Jan 2012 at 15:05, David Savage <dsav...@cytelcom.com> wrote: 

> I open the html file up from a windows explorer window (Q:\asterisk\), and so
> IE opens it up, but the problem lies in the fact that I cannot find apache
> service running in the background...haven't figured out why yet.  The "test
> configuration" start menu option (under "configure apache server") just
> displays a console window for a brief moment, then immediately disappears. 
> The icon I see near my time says "Running none of 1 Apache services"....So I
> have to get that straightened out first...I believe that's been my problem all
> along.

Well, that's going to be part of it, but it's never going to work if you open 
it via Explorer. If you do that, apache won't be involved whether it's running 
or not. This will only work if you have IE (or other browser) open and put 
http://localhost/your-webpage.html into the browser's address bar. Further, 
both the webpage and PHP file need to be in your document-root. Look in your 
apache config file for that).

--
Cheers  --  Tim

--- End Message ---

Reply via email to