473,587 Members | 2,547 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class method returns both TRUE and FALSE at the exact same time!!

[PHP]
class ThumbView extends PaginationView {

function ThumbView() {}

/**
* Determine if the original image is actually an image and thus a
thumbnail can be generated at all
*
* @access public
* @param mixed $image_name (optional)
* @param mixed $album (optional)
* @param mixed $section (optional)
* @return boolean
* @see mime_content_ty pe
* @see actual_path
*/
function isImage($image_ name = '', $album = '', $section = '')
{ // BOOLEAN METHOD
/*--------------------------------------------------------------------------------------------------------------------------------------------------------
ResizeView will inherit ThumbView::isIm age() method now and thus
will have its own instance of $this->id in existence
which is the image name and not an actual id (other instances of
$this->id in class objects inheriting this method will
be numeric by database design). Set the obtainably inherited
$this->{$section . '_name'} to $this->id.
---------------------------------------------------------------------------------------------------------------------------------------------------------*/
if (!$section) global $section;
global ${$section . 'LocationPath'} ;
if (!$this->{$section . '_name'} || $image_name)
ThumbView::setT humbViewPropert ies($image_name , $album);
if ($this->{$section . '_name'}) {
if (strlen($this->album) 0) $album = $this->album;
$locationPath = ($album) ? "${$section . 'LocationPath'}/$album" :
${$section . 'LocationPath'} ;
$imgStatArray = @getimagesize(a ctual_path("$lo cationPath/" .
$this->{$section . '_name'}));
if (!is_array($img StatArray) || @sizeof($imgSta tArray) == 0) return
false;
print_r("111<P> ");
if (preg_match('/^image\//i',
@mime_content_t ype(actual_path ("$locationP ath/" . $this->{$section .
'_name'})))) return true;
print_r("222<P> ");
}
print_r("333<P> ");
return false; // WILL EVEN RETURN FALSE IF NO IMAGE NAME IS PROVIDED
SINCE IMPOSSIBLE TO DETERMINE IF ?? IS AN IMAGE OR NOT
}

}

[/PHP]

This class method, isImage(), for some bizarre reason, has the uncanny
ability to return both TRUE **AND** FALSE literally at the exact same
time, or so it seems!

This will be your output:

111
333
Based on this logic flow, that means that it should have returned true
and that's it, but for some bizarre reason it is literally capable of
returning true, then suddenly returning false, even though the method
is called "statically ":

[PHP]
if (!ThumbView::is Image($fileName , $_REQUEST['album'])) {
print_r("This is not an image<P>"); // ALWAYS PRINTS THIS EVEN IF IT
*IS* AN IMAGE!!
}
[/PHP]

Has anyone ever seen this within a statically called class method ever
in PHP?

Phil

Jul 24 '06 #1
3 1639
*** comp.lang.php escribió/wrote (24 Jul 2006 14:49:55 -0700):
[PHP]
class ThumbView extends PaginationView {
I can't really understand your question. But I'll provide a couple of
hints:

1) The return statement causes the method to end its execution immediately.
How can you have two return values *at the same time*?

2) You need to use brackets if you want more than one sentence within a
control structure. So:

if($foo)
bar();

works as expected.

if($foo)
bar();
print_r('666');

doesn't: print_r() is out of the if() block so it's always executed.

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia .com
+- Mi web de humor con rayos UVA: http://www.demogracia. com
--
Jul 25 '06 #2
ronverdonk
4,258 Recognized Expert Specialist
Are you sure your output isn't
Expand|Select|Wrap|Line Numbers
  1. 111
  2. 222
  3. 333
  4.  

Ronald :cool:
Jul 25 '06 #3

Alvaro G. Vicario wrote:
*** comp.lang.php escribió/wrote (24 Jul 2006 14:49:55 -0700):
[PHP]
class ThumbView extends PaginationView {

I can't really understand your question. But I'll provide a couple of
hints:

1) The return statement causes the method to end its execution immediately.
How can you have two return values *at the same time*?

2) You need to use brackets if you want more than one sentence within a
control structure. So:

if($foo)
bar();

works as expected.

if($foo)
bar();
print_r('666');

doesn't: print_r() is out of the if() block so it's always executed.
I know this, but thanx again for the general reminder.

I wound up rewriting the entire class with local conditional
self-instantiation and utilized that for further method execution and
it works! Returns "just once" this time.

Phil
>

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia .com
+- Mi web de humor con rayos UVA: http://www.demogracia. com
--
Jul 25 '06 #4

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

Similar topics

0
2703
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2: The name of the second array $formField1CompareWith: String to use as my comparison basis for first array. Defaults to using $val unless it's 'key'...
8
1571
by: Nick | last post by:
I have the following code: var obj = {a:0, b:1, ...} function f() {...} obj.f = f // This will make a instance method? How to make a Class method for the class of obj? Or what's the class of "obj"?
10
1651
by: lkrubner | last post by:
I killed last night and a good chunk of today trying to figure out this one particular attempt to get a class and initialize it. My code is using a class method called getObject to include() a file and then initialize the class in that file (one class per file, each file has the same name as the class). This code has been working fine for 8...
11
2171
by: John Moore | last post by:
Hi, I must be missing something obvious. I cannot get this function to run the update query on Line 6, although the call to run the query evaluates true, and both update_cat_total functions execute, while the function itself returns true. A var_dump shows that all the variables are valid, and I can run the exact same update query at...
48
30092
by: Skybuck Flying | last post by:
Hi, I came across this C code which I wanted to understand etc it looked like this: if (-1) etc It made me wonder what the result would be... true or false ? In C and Delphi
59
4568
by: Pierre Quentel | last post by:
Hi all, In some program I was testing if a variable was a boolean, with this test : if v in My script didn't work in some cases and I eventually found that for v = 0 the test returned True So I changed my test for the obvious "if type(v) is bool", but I still find it confusing that "0 in " returns True
40
2706
by: nufuhsus | last post by:
Hello all, First let me appologise if this has been answered but I could not find an acurate answer to this interesting problem. If the following is true: C:\Python25\rg.py>python Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) on win32 Type "help", "copyright", "credits" or "license" for more
1
3012
by: ramiatia | last post by:
Hi all, I'm writing a Win32 app with VC 2005 unmannaged code. I started a new project from scratched. I want to have a class for the Dialog form that handle everyting for that form (processing messages and so on...). In the WinMain() I want to create an object of the class I wrote. Because DefProc is a CALLBACK function, i'm having hard time...
12
2661
by: ross.oneill | last post by:
Hi, Is there any function in php that will match a word exactly and if it finds it, it returns true. For example if I search for "CA" strVar = "Bob is from Los Angeles CA" - return true strVar "Bob is from Canada" -- returns false
0
7849
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...
0
8215
Oralloy
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. ...
0
8347
jinu1996
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...
1
7973
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...
0
6626
agi2029
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...
0
5394
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...
0
3844
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...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1189
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...

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.