php-general Digest 7 Oct 2009 08:38:41 -0000 Issue 6378
Topics (messages 298692 through 298710):
Re: ternary operator sintax help
298692 by: Tom Worster
298693 by: MEM
Re: Sessions in databases]
298694 by: Kim Madsen
Re: Whacky increment/assignment logic with $foo++ vs ++$foo
298695 by: Andrea Giammarchi
298696 by: Andrea Giammarchi
298697 by: Andrea Giammarchi
298698 by: Andrea Giammarchi
298699 by: Andrea Giammarchi
298700 by: clancy_1.cybec.com.au
298701 by: tedd
298702 by: tedd
298703 by: Daevid Vincent
298704 by: Daevid Vincent
298705 by: Robert Cummings
298706 by: Andrea Giammarchi
298707 by: clancy_1.cybec.com.au
Insult my code!
298708 by: Eric Bauman
298710 by: Mert Oztekin
Output buffering
298709 by: Arno Kuhl
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 ---
just as ashley said it.
On 10/6/09 3:26 PM, "MEM" <[email protected]> wrote:
> Sorry all,
> It's ok. The sintax:
>
> <?php echo (isset($erros['anexo']) ? '<div
> class="mensagemErro">'.$erros['anexo'].'</div>' :''); ?>
>
> Was right all the time.
>
> Anyway, I've learn something new: having a var with '' is not the same thing
> as not been unset. So we must pay attention on what cases we use isset, or
> !empty.
>
>
> Thanks a lot,
> Márcio
>
>> -----Original Message-----
>> From: João Cândido de Souza Neto [mailto:[email protected]]
>> Sent: terça-feira, 6 de Outubro de 2009 19:53
>> To: [email protected]
>> Subject: [PHP] Re: ternary operator sintax help
>>
>> <?= (isset($erros['anexo']) ? '<div
>> class="mensagemErro">'.$erros['anexo'].'</div>' :''); ?>
>>
>> ""MEM"" <[email protected]> escreveu na mensagem
>> news:002401ca46b4$ed6ad6a0$c84083...@com...
>> Hello all,
>>
>> I'm trying to display a div, only when some php value is set.
>> Since this will be near html, I'd like to keep it on one line. So, I'd
>> love
>> to use shortcuts and a ternary operator for the effect.
>>
>> I'm having something like this right now, but the div still appears
>> even if
>> the error is NOT set.
>>
>> <?= (isset($erros['anexo'])) ? '<div class="mensagemErro">'
>> .$erros['anexo'].'</div>' :''; ?>
>>
>> :(
>>
>> Can I have your help with the right syntax ?
>>
>>
>> Regards,
>> The newbie on a Humpty Dumpty wall,
>> Márcio
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Absolutely. ;) I was reporting to ashley teachings. :-)
Philip, thanks for the tip.
:-)
Thank you all,
Márcio
> -----Original Message-----
> From: Tom Worster [mailto:[email protected]]
> Sent: terça-feira, 6 de Outubro de 2009 21:10
> To: MEM; [email protected]
> Subject: Re: [PHP] Re: ternary operator sintax help
>
> just as ashley said it.
>
>
> On 10/6/09 3:26 PM, "MEM" <[email protected]> wrote:
>
> > Sorry all,
> > It's ok. The sintax:
> >
> > <?php echo (isset($erros['anexo']) ? '<div
> > class="mensagemErro">'.$erros['anexo'].'</div>' :''); ?>
> >
> > Was right all the time.
> >
> > Anyway, I've learn something new: having a var with '' is not the
> same thing
> > as not been unset. So we must pay attention on what cases we use
> isset, or
> > !empty.
> >
> >
> > Thanks a lot,
> > Márcio
> >
> >> -----Original Message-----
> >> From: João Cândido de Souza Neto [mailto:[email protected]]
> >> Sent: terça-feira, 6 de Outubro de 2009 19:53
> >> To: [email protected]
> >> Subject: [PHP] Re: ternary operator sintax help
> >>
> >> <?= (isset($erros['anexo']) ? '<div
> >> class="mensagemErro">'.$erros['anexo'].'</div>' :''); ?>
> >>
> >> ""MEM"" <[email protected]> escreveu na mensagem
> >> news:002401ca46b4$ed6ad6a0$c84083...@com...
> >> Hello all,
> >>
> >> I'm trying to display a div, only when some php value is set.
> >> Since this will be near html, I'd like to keep it on one line. So,
> I'd
> >> love
> >> to use shortcuts and a ternary operator for the effect.
> >>
> >> I'm having something like this right now, but the div still appears
> >> even if
> >> the error is NOT set.
> >>
> >> <?= (isset($erros['anexo'])) ? '<div class="mensagemErro">'
> >> .$erros['anexo'].'</div>' :''; ?>
> >>
> >> :(
> >>
> >> Can I have your help with the right syntax ?
> >>
> >>
> >> Regards,
> >> The newbie on a Humpty Dumpty wall,
> >> Márcio
> >>
> >>
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
--- End Message ---
--- Begin Message ---
Sam Stelfox wrote on 2009-10-06 18:09:
If you are distributing your application over multiple servers, using a
database for session tracking allows a user to continue there session
regardless of which server their request bounces too. It prevents the
need for 'sticky' network connections which time out anyways.
I know Alfio don't have access to the php.ini file, but if you do and
have the above setup, consider using a tmp dir like /phptmp and have one
root server and mount the other servers /phptmp to the root servers /phptmp
Kind regards
Kim Emax
Il pinguino volante wrote:
(There were some erroros in the previous email, I'm sorry)
Hi to all.
I have to realize an authentication system for a lot of users.
I heard that someone uses to store session states (?) into a database.
I'd like to know how and, expecially, WHY to do it and what's would be
better (considering that I CANNOT -d'oh!- edit the php.ini file).
Thanks in advance,
Alfio.
--- End Message ---
--- Begin Message ---
> Furthermore, the amount
> of time micro-optimization takes up (going through old code, I mean)
> could be better spent doing something that actually does increase your
> performance, like implementing a search engine or memcached. Going
> forward, if you're aware that ++i and i++ are the same for your
> application and ++i is a single php opcode faster (which I don't know
> if it's even measurable, that difference), sure go ahead and use ++i
> but it's certainly not worth serious thought or developer time.
>
> My two cents.
I do micro optimization with every language I use, when I know, and where I
can. I am the one that usually solves slow query problems, and I use best
practices on database as well.
Guys, I don't get your point ... if you know that "$var" is a non-sense, feel
free to use it ... what I know, is that every double quoted string require
parsing, due to variable or char evaluations (\x00) evaluation, if I don't need
this waste of time, why should I write a totally meaningless, useless, "$var"
where $var is sufficient or more over 'whatever'.$var will be faster?
The fact is that this is my approach for every layer of an application, I am
not like that only with PHP. There is something to optimize? Make it your code
style and you won't spend a sinlge second more than any other, but at least
you'll do your best to reach best performances.
As I have said, I have never had performances problem, and I am a full web
stack developer, but you can obviously do whatever you want, is still a matter
of points of view.
Regards
_________________________________________________________________
Windows Live: Keep your friends up to date with what you do online.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010
--- End Message ---
--- Begin Message ---
ah ah ah .... that's for sure, I've never said that is correct, I said that is
illogical ;-)
> Subject: RE: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
> Date: Tue, 6 Oct 2009 12:46:36 -0500
> From: [email protected]
> To: [email protected]; [email protected]; [email protected]
>
> [snip]
> ...micro optimizations...
> [/snip]
>
> And in the land of micro optimization you would likely never see the
> following;
>
> $a = $a++;
_________________________________________________________________
Windows Live: Keep your friends up to date with what you do online.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010
--- End Message ---
--- Begin Message ---
> Eddie:
>
> And thanks for supporting my point.
so you think as well that 3 characters, written like this i++, in a careless
way, or like this ++i, make the difference about time spent to develop ...
interesting
Regards
_________________________________________________________________
Windows Live: Keep your friends up to date with what you do online.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010
--- End Message ---
--- Begin Message ---
> Speaking of starting a conversation, what do you think about the "goto"
> construct introduced just recently?
if used properly, could avoid recursion, and speed up operations ... there is
nothing wrong with goto, everything we write on lowest level is a jump in the
memory (as goto is a jump in the code flow)
++goto ... and not goto++
Regards
_________________________________________________________________
Windows Live: Make it easier for your friends to see what you’re up to on
Facebook.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092009
--- End Message ---
--- Begin Message ---
> if used properly, could avoid recursion, and speed up operations ... there is
> nothing wrong with goto, everything we write on lowest level is a jump in the
> memory (as goto is a jump in the code flow)
>
> ++goto ... and not goto++
I forgot, I have always used goto in Batch script, which indeed can emulates
functions, except there is no recursion problem. I have a couple of batches
online if interesting, and from performances point of view, ask yourself why on
earth PHP core developers have introduced goto and actually somebody is using
it ;-)
Uh, I forgot I live in microoptimization land ... lol
_________________________________________________________________
Keep your friends updated—even when you’re not signed in.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010
--- End Message ---
--- Begin Message ---
On Tue, 6 Oct 2009 14:08:14 -0400, [email protected] (tedd) wrote:
>At 10:48 AM -0300 10/6/09, Martin Scotta wrote:
>>No matter how silly it can looks like (a = a++) it is still completely valid
>>code and it SHOULD run without problems.
>
>Yeah, it's a valid as:
>
> $a = $a;
>
>and does the same thing, which is nothing.
No; it's worse, because it can be interpreted in two different ways, which is
demonstrated
by the fact that it gives different results in different languages.
>If you want a statement that does something, then use:
>
> $a = ++$a;
>
>or simply:
>
> $a++;
>
>or
>
> ++$a;
>
>Any of those will increment $a, whereas ($a = $a++;) does nothing.
According to Schlossnagel "Advanced PHP programming" it is better to use ++$a,
because
this simply increments the variable, whereas $a++ makes a copy, and then
increments the
variable, so it involves additional time and memory usage. I cannot see that it
would ever
make a difference in the real world, but this is one of the tricks Schlossnagel
advises
you should use when you want the fastest possible code.
--- End Message ---
--- Begin Message ---
At 1:09 AM +0200 10/7/09, Andrea Giammarchi wrote:
> Eddie:
And thanks for supporting my point.
so you think as well that 3 characters, written like this i++, in a
careless way, or like this ++i, make the difference about time spent
to develop ... interesting
No, just the opposite. It doesn't make any difference either way.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
At 10:20 AM +1100 10/7/09, [email protected] wrote:
On Tue, 6 Oct 2009 14:08:14 -0400, [email protected] (tedd) wrote:
At 10:48 AM -0300 10/6/09, Martin Scotta wrote:
No matter how silly it can looks like (a = a++) it is still completely valid
code and it SHOULD run without problems.
Yeah, it's a valid as:
$a = $a;
and does the same thing, which is nothing.
No; it's worse, because it can be interpreted in two different ways,
which is demonstrated
by the fact that it gives different results in different languages.
That's true for different languages, but I was talking about php. In
some languages even the variable $a wouldn't be legal.
However, you are correct that the confusion such assignments would
raise would create problems as well.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Paul M Foster [mailto:[email protected]]
> Sent: Tuesday, October 06, 2009 6:28 AM
> To: [email protected]
> Subject: Re: [PHP] Whacky increment/assignment logic with
> $foo++ vs ++$foo
>
> On Tue, Oct 06, 2009 at 08:51:17AM -0400, Bob McConnell wrote:
>
> > From: Joost [mailto:[email protected]]
> > > "Daevid Vincent" wrote:
> > >>> From: Ben Dunlap [mailto:[email protected]]
> >
> > > $a = $a++;
> >
> > I just think this is an ambiguous line of code that wasn't thought
> > through. The presence of the postfix operator makes the result
> > undefined, no matter what language you are using. It will
> be an accident
> > if you get the results you are expecting.
>
> The behavior of the ++ operator is the invention of Kernighan
> and Ritchie.
> I don't imagine they ever foresaw anyone doing something as silly as
>
> a = a++;
>
> except under the rarest of circumstances.
>
> Paul
Except that:
$a = 123;
$b = $a++;
echo $b; //gives 123, not 124
as you logically expect it to and common sense would dictate, regardless of
what K&R or anyone else says.
--- End Message ---
--- Begin Message ---
HEY! Don't try to hijack my astonishingly long-running thread! Start your
own Jay. ;-}
> -----Original Message-----
> From: Jay Blanchard [mailto:[email protected]]
> Sent: Tuesday, October 06, 2009 11:34 AM
> To: Tommy Pham; [email protected]
> Subject: RE: [PHP] Whacky increment/assignment logic with
> $foo++ vs ++$foo
>
> [snip]
> I find it interesting for a discussion to go on this long for
> something
> as
> $a = $a++;
> [/snip]
>
> You think that is interesting? Start a conversation about these
>
> {}
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Andrea Giammarchi wrote:
if used properly, could avoid recursion, and speed up operations ... there is
nothing wrong with goto, everything we write on lowest level is a jump in the
memory (as goto is a jump in the code flow)
++goto ... and not goto++
I forgot, I have always used goto in Batch script, which indeed can emulates
functions, except there is no recursion problem. I have a couple of batches
online if interesting, and from performances point of view, ask yourself why on
earth PHP core developers have introduced goto and actually somebody is using
it ;-)
Uh, I forgot I live in microoptimization land ... lol
If you read the archives for PHP Internals you can view the discussion
that went into the final decision to include GOTO. It happened 2 or 3
years ago and I was certainly on the side arguing in its favour. The
GOTO used in languages such as C and now PHP, is not the bastard GOTO of
BASIC yesteryear. There are certainly use cases where the use of GOTO
makes far more sense than other constructs. Finite state machines (often
used in parsing) are one such place. In fact if you grep for goto on any
major open source project's C code, you will probably find multiple
occurrences. PHP, MySQL, and Apache all use goto.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
> So while we can debate computing considerations of today, tomorrow
> those will be less important. That was the point I was making. Why
> not focus on things that make significant difference and let the
> insignificant fade into history.
I tendentiously focus on all things able to make, all together, even more
significant difference.
Some micro-optimization, used as common code style, can make the entire
application or the specific performance critical task, possible, even with an
embed language as PHP is.
++$i is not different, from my point of view, from a code where each sequential
push is performed via array_push($arr, $value) rather than $arr[] = $value;
Same is for all those loop such
for($i = 0; $i < count($staticStack); $i++);
for me alien, since I've always done
for($i = 0, $length = count($staticStack); $i < $length; ++$i);
or, even better, a core performed loop when I need values
foreach($staticStack as $value);
these are just examples, code style, whatever you want, and I'll never change
my style unless there is a valid reason and some bench able to demonstrate I am
wrong. I guess it's just a matter of point of views, but I cannot suggest
slower practice cause Moore said tomorrow that CPU will strike the millisecond,
'cause on micro benchmarks, we can go faster, and that's it.
Regards
_________________________________________________________________
Windows Live: Keep your friends up to date with what you do online.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010
--- End Message ---
--- Begin Message ---
On Tue, 6 Oct 2009 12:15:54 -0400, [email protected] (tedd) wrote:
>At 3:56 PM +0200 10/6/09, Andrea Giammarchi wrote:
>> > Does these behaves exactly?
>>> for($i=0; $i<10; ++$i)
>>> for($i=0; $i<10; $i++)
>>
>>different benchmarks showed ++$i is usually faster than $i++
>
>"Faster" is a relative term that is becoming more meaningless each year.
>
>Considering that "speed" is increasing and "memory" prices are
>dropping exponentially, both of those are becoming less and less
>important in design considerations (my opinion).
>
>The speeds of the Crays of yesteryear we are now holding in our hands
>as cell phones. The memory we are buying today is literally fractions
>of a cent of the tens of thousands of dollars we spent some 20 years
>ago.
My memory is a bit vague, but I think my first hard disk had 10 MB, and cost
about $2000--
about $0.20 a kilobyte. Now you can buy a 1 TB hard disk for less than $100 --
less than
$0.10 a gigabyte.
>I venture to claim the time it took me to write this email (and for
>you to read it) was longer than the total time saved between using
>++$i vs $i++ for all the php scripts in the world over the remaining
>life span of PHP.
>
>Interesting "food for thought", huh?
When I started computing I could get five runs a week if I used the little
"local"
computer (with 32K of 24 bit words, and costing $500,000), or three runs a week
if I used
the big computer in Canberra (which had four times as much memory and cost $2
million).
--- End Message ---
--- Begin Message ---
Hi there,
I'm in the process of trying to wrap my head around MVC, and as part of
that, I'm attempting to implement a super-tiny MVC framework.
I've created some mockups of how the framework might be used based
around a very simple 'bank', but I'm trying to get some feedback before
I go and implement it, to make sure I'm actually on the right track.
Any thoughts would be much appreciated!
Model - http://www.pastebin.cz/23595
Controller - http://www.pastebin.cz/23597
View - http://www.pastebin.cz/23598
Template - http://www.pastebin.cz/23599
--- End Message ---
--- Begin Message ---
Seems ok.
Just a thought:
Your model seems to be coded just for retreiving data. IMO you should
code it for all possible actions(insert,update,delete,select). And also it
should run without any database calls(you may create a new bank user in a page
and use it than throw it away, so you wont have to need a database to save it).
Your model may be more useable when it can holds the data
itself(without retreiving it from db first), after that a save() method may
inserts/updates it to db.
-----Original Message-----
From: Eric Bauman [mailto:[email protected]]
Sent: Wednesday, October 07, 2009 9:35 AM
To: [email protected]
Subject: [PHP] Insult my code!
Hi there,
I'm in the process of trying to wrap my head around MVC, and as part of
that, I'm attempting to implement a super-tiny MVC framework.
I've created some mockups of how the framework might be used based
around a very simple 'bank', but I'm trying to get some feedback before
I go and implement it, to make sure I'm actually on the right track.
Any thoughts would be much appreciated!
Model - http://www.pastebin.cz/23595
Controller - http://www.pastebin.cz/23597
View - http://www.pastebin.cz/23598
Template - http://www.pastebin.cz/23599
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Bu mesaj ve ekleri, mesajda gönderildiği belirtilen kişi/kişilere özeldir ve
gizlidir. Size yanlışlıkla ulaşmışsa lütfen gönderen kisiyi bilgilendiriniz ve
mesajı sisteminizden siliniz. Mesaj ve eklerinin içeriği ile ilgili olarak
şirketimizin herhangi bir hukuki sorumluluğu bulunmamaktadır. Şirketimiz
mesajın ve bilgilerinin size değişikliğe uğrayarak veya geç ulaşmasından,
bütünlüğünün ve gizliliğinin korunamamasından, virüs içermesinden ve bilgisayar
sisteminize verebileceği herhangi bir zarardan sorumlu tutulamaz.
This message and attachments are confidential and intended for the
individual(s) stated in this message. If you received this message in error,
please immediately notify the sender and delete it from your system. Our
company has no legal responsibility for the contents of the message and its
attachments. Our company shall have no liability for any changes or late
receiving, loss of integrity and confidentiality, viruses and any damages
caused in anyway to your computer system.
--- End Message ---
--- Begin Message ---
Has there been a change to the way output buffering works?
The manual states for ob_get_contents()
"This will return the contents of the output buffer or FALSE, if output
buffering isn't active."
But the following works in php4.4.4 and php5.2.6 whether output buffering is
on or not
<?php
ob_start();
echo "<html><body>";
echo "output_buffering is ";
echo ini_get('output_buffering')?"on":"off";
echo "</body></html>";
$check = ob_get_contents();
if ($check === FALSE)
echo " FALSE";
$info = ob_get_contents();
ob_clean();
echo $info." -2-";
ob_flush();
?>
The output is "output_buffering is off -2-" (or on) displayed once - "FALSE"
is obviously never appended.
According to the manual I shouldn't see anything at all when
output_buffering is off (or if memory serves me correctly I should see an
error about "headers already sent" or something). Looking at phpinfo
confirms the value echoed by the script. Has something changed with output
buffering?
Cheers
Arno
--- End Message ---