473,608 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return statement

What happens when you take the value returned by a function that
doesn't return a value? For example,

function myfunc($myvar) {
if ($myvar == "xyzzy")
return(1);

return;
}

$abc = myfunc("def");

I know from my days of c programming that this would be very bad to
do. But php gives you so rope I'm wondering if you could just do an
isset($abc) to see if myfunc returned a value.

If so then we could write (scary) code where on an error condition
instead of returning something like -1 you just don't return a value.
Jul 16 '05 #1
3 3868
On 17 Jul 2003 12:29:54 -0700, Rusty Wright <ru***@socrates .Berkeley.EDU>
wrote:
What happens when you take the value returned by a function that
doesn't return a value? For example,

function myfunc($myvar) {
if ($myvar == "xyzzy")
return(1);

return;
}

$abc = myfunc("def");

I know from my days of c programming that this would be very bad to
do. But php gives you so rope I'm wondering if you could just do an
isset($abc) to see if myfunc returned a value.

If so then we could write (scary) code where on an error condition
instead of returning something like -1 you just don't return a value.


Ask PHP...

<pre>
<?php
function f() {
return;
}
var_dump(f());
?>
</pre>

Outputs:

NULL
http://uk.php.net/manual/en/language.types.null.php

--
Andy Hassall (an**@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #2
I prefer using isset(). If a function has an error it just uses
return; and you do an isset() to see if there was an error.

The question wasn't meant as an "is this possible" but more of an idea
to discuss to see what people thought of it.
Jul 16 '05 #3
On 17 Jul 2003 13:14:42 -0700, Rusty Wright <ru***@socrates .Berkeley.EDU>
wrote:
I prefer using isset(). If a function has an error it just uses
return; and you do an isset() to see if there was an error.
Well... more accurate would probably be is_null()

isset will return FALSE for NULL, since it's set to NULL, not 'not set'.
(erm..)

<?php
function f() {
}
$x = f();
if (!isset($x)) {
print "not isset\n";
}
if (is_null($x)) {
print "is_null\n" ;
}
?>

not isset
is_null
The question wasn't meant as an "is this possible" but more of an idea
to discuss to see what people thought of it.


I prefer the usual style of returning 'something' for success, or Boolean
false for failure - which you can check for using === (so you don't mistake a
valid 0 or empty-string return).

--
Andy Hassall (an**@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
2142
by: John Bailo | last post by:
The c# *return* statement has been bothering me the past few months. I don't like the fact that you can have different code paths in a method and have multiple return statements. To me, it would be more orthogonal if a method could only have one return statement. --
3
2777
by: Test | last post by:
Sorry, some people may have asked this question before. It is really hard to find relevant articles about this topic on the web using key words. I know it is not recommended to use return statement in constructor. But, 1. How about a return statement without any return value? Does the execution of the constructor stop at the return statement? 2. How does the compiler handle the return statement with a value? Does it just give a warning?
4
45187
by: bluedolphin | last post by:
This is my first function in Visual and I'm having a simple syntax syntax issue that I'm hoping someone can help correct for me. I have a function Public Function Sub_Agg_Embedded_Catgeories(Pass_Report_Type_Desc As String, other variables, ....) As Integer I call it with the statement intReturn = Sub_Agg_Embedded_Gender(Pass_Report_Type_Desc, other variables)
10
2599
by: LaEisem | last post by:
On-the-job, I have "inherited" a lot of old C language software. A question or two about when "casting" of null pointer constants is needed has occurred during behind-the-scenes cleanup of some of that software. That subject seems not to be addressed, at least not directly, in the C FAQ where FAQ 5.2 seems most relevant. References: * C FAQ 5.2 Null pointers (Including conditions where "casting" of null pointer...
3
2371
by: Marlene Stebbins | last post by:
My program has code like this: bigint bigSub(bigint minuend, bigint subtrahend) { bigint bigdiff; bigInit(&bigdiff); if(((cmp_ops(minuend.number, subtrahend.number))==1) && minuend.sign == POS && subtrahend.sign == POS)
15
6722
by: Greenhorn | last post by:
Hi, when a function doesn't specify a return type ,value what value is returned. In the below programme, the function sample()is returning the value passed to 'k'. sample(int); main() { int i = 0,j; j = sample(0);
6
2262
by: lovecreatesbeauty | last post by:
I ever missed a `return' statement when write a function `int HighDigit(Num)' to get the highest digit of an integer. But even if the `return' statement is ignored the function still can obtain an `correct' return value when the argument `Num' is larger than or equal to the Macro `NUM_SYS'. If the argument is less than the Macro, the function without a `return' get an undefined value. I've made a test on Ms Windows 2000 and VC 6.
15
2794
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
13
1859
by: jimjim | last post by:
Hello all, I ve come across the following code fragment and I was wondering why is the copy ctr called on return (rather than just returning the string statement obj. TIA string PublishedProductsRepo :: CreateStatement() const { string statement;
7
10307
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As Integer) As Boolean Private Function IsLvItemChecked(ByVal ClientID As Integer) As Boolean If lvServers.InvokeRequired = True Then lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf IsLvItemChecked),...
0
8010
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8349
tracyyun
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...
1
6015
isladogs
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...
0
5479
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3967
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4030
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2477
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
0
1336
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.