Hi!
In while (false !== ($file = readdir($handle )))
what happens?
The $file gets assigned, and the value of that is compared with false?
The assignment is being compared with false
Say, I want to return true or an error code. Can I do;
if($err = somefunc())
echo "ok"
else
echo "error: $err";
WBR
Sonnich
Nov 28 '07
12 1253
Jerry Stuckle wrote:
taps128 wrote:
>Toby A Inkster wrote:
>>jodleren wrote:
$err = somefunc(); if($err===tr ue) echo "ok" else echo "error: $err";
echo (true === ($err = somefunc())) ? 'ok' : "error: $err";
:-)
or more readable(to me) IMHO $err=foo(); switch($err) { case true: echo 'ok';break; case false: echo 'error: '.$err; }
But of course thats just a matter of style.
More than a matter of style. If the function returns '1', your way will
print 'ok', while Toby's function will return the more correct 'error: 1'.
You right, i missed those '==='
Gordon wrote:
On Nov 29, 1:22 pm, Toby A Inkster <usenet200...@t obyinkster.co.u k>
wrote:
>taps128 wrote:
>>or more readable(to me)
Readable perhaps, but boring. echo (true === ($err = somefunc())) ? 'ok' : "error: $err"; is fun. It invites the reader to explore its mysteries; to embark in a journey of discovery, a quest filled with a sense of awe and wonder. And in a sense it helps the reader to uncover new things about *themselves* and unfold the secrets of their very souls.
Plus it saves almost 30 bytes.
-- Toby A Inkster BSc (Hons) ARCS [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux] [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 4 days, 20:07.] [Now Playing: Keane - On a Day like Today]
Sharing Music with Apple iTunes http://tobyinkster.co.uk/blog/2007/1...tunes-sharing/
And is completely contrary to the principles of writing maintainable
code. :) What code does should be self-evident, or at least self-
explanatory and well commented, because the poor sod who has to look
at the code in 18 months time to figure out why it's not behaving as
intended might be you.
The ternary operator should not be 'confusing' to any competent PHP
programmer. Don't just leave out the parts that "Aren't your style".
Because you will come unstuck one day, when you don't understand
something that is normal and quite common.
besides,
echo(true===$e= somefunc())?'ok ':"error: $e";
saves even more bytes ;)
- Michael
Toby A Inkster <us**********@t obyinkster.co.u kwrote:
> Readable perhaps, but boring. echo (true === ($err = somefunc())) ? 'ok' : "error: $err"; is fun. It invites the reader to explore its mysteries; to embark in a journey of discovery, a quest filled with a sense of awe and wonder. And in a sense it helps the reader to uncover new things about *themselves* and unfold the secrets of their very souls.
+1 QOTW
I have to write that down. That has to be both the best and the worst
justification for obfuscated code that I've ever read.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ben |
last post by:
Hi all,
This may sound easy but I'm having trouble assigning values to array
element. My problem is as follows:
m =
for o in m:
# Here first o is 'Peter'.. I want to do something like this:
Peter = 10
|
by: fAbs |
last post by:
hi, when I do:
someclass &someobject = someotherobject;
it asigns the reference of someotherobject to the variable 'someobject' that
you just declared. SO that basically
someobject and someotherobject are really the same variable with two names.
but if I do:
someclass someobject;
|
by: KathyB |
last post by:
Hi, figured out where I was going wrong in my post just prior, but is
there ANY way I can assign several variables to then use them in an
Update statement, for example (this does not work):
ALTER PROCEDURE dbo.UpdateXmlWF
(
@varWO varchar(50)
)
AS
DECLARE @varCust VARCHAR(50)
|
by: Dave |
last post by:
I am trying to create a function in SQL 2000. Im rusty on function
syntax and need to also assign some variables for use within this
function.
Example:
create function blah (@param1 int)
declare @var1 int, @var2 int
--it doesnt like this method of assigning values to my
|
by: vanGogh |
last post by:
I have generated classes based on an Xml schema file (xsd) using the XSD.exe tool.
My goal is to:
- write an application that can parse XML documents
- fill objects (based on the generated classes) with the XML data in element nodes or attributes
- assemble the objects so they are contained in their parent
- add the resulting object to an arrayList
The problem I’m having is that I am not sure how to go about assigning an object to...
| |
by: Jon |
last post by:
This seems strange, but maybe there's some basic concept I'm missing.
When I assign one class member to another, any methods that are applied
to one are applied to both variables.I can't get the code below to work
(display sum, product and quotient) without re-initializing z1 each
time. What's the problem here?
Dim z0 As Complex = New Complex(CDbl(Me.TextBox1.Text),
CDbl(Me.TextBox2.Text))
Dim z1 As Complex = New...
|
by: weston |
last post by:
I've got a piece of code where, for all the world, it looks like this
fails in IE 6:
hometab = document.getElementById('hometab');
but this succeeds:
hometabemt = document.getElementById('hometab');
Has anyone ever seen anything like this before, or am I dreaming?
|
by: =?Utf-8?B?VHJlY2l1cw==?= |
last post by:
Hello, Newsgroupians:
I have a large class with a lot of member variables. I also have a function
in the class that I would like to change ALL Of the member variables. I am
trying to assign "this" to the result, but I always get the error message,
"Cannot assign to '<this>' because it is read-only."
I've been searching on the Internet, and I notice some C# code is violating
this rule. Perhaps their code is wrong.
|
by: jodleren |
last post by:
Hi
I have been looking into php.net, but could not find any proper
description.
There is a way of assigning variables from functions, while at the
same time using them in e.g. an if.
I have tried to use this, but failed.... and I have not found any
proper information about this?
E.g., if I am right, then
|
by: shortyzms |
last post by:
I'm having a problem with assigning 64-bit hex values to unsigned long variables in MS VS2005 c++ compiler.
unsigned long Number;
Number = 0x1000000000000000UL;
After this declaration and assignment, the value in Number is always 0. However, if the hex value is 0x0000000000000001, then the value is 1 as expected. It seems like the compiler is truncating the most significant 32 bits. How can I make this work?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |