473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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_type
* @see actual_path
*/
function isImage($image_name = '', $album = '', $section = '')
{ // BOOLEAN METHOD
/*--------------------------------------------------------------------------------------------------------------------------------------------------------
ResizeView will inherit ThumbView::isImage() 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::setThumbViewProperties($image_name, $album);
if ($this->{$section . '_name'}) {
if (strlen($this->album) 0) $album = $this->album;
$locationPath = ($album) ? "${$section . 'LocationPath'}/$album" :
${$section . 'LocationPath'};
$imgStatArray = @getimagesize(actual_path("$locationPath/" .
$this->{$section . '_name'}));
if (!is_array($imgStatArray) || @sizeof($imgStatArray) == 0) return
false;
print_r("111<P>");
if (preg_match('/^image\//i',
@mime_content_type(actual_path("$locationPath/" . $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::isImage($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 1624
*** 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 Expert 4TB
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
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2:...
8
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...
10
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...
11
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...
48
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
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 ...
40
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...
1
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...
12
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 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.