Re: [PHP] error handling and __LINE__

2001-11-27 Thread SafeV

Thanks, assert() is cool, but it still reports the filename and line 
number of the included file with the function in which the error 
occurred, not the script that called the functon with illegal arguments.
Or...???

Eg.:
index.php:
?
include_once(functions.php); 
// foo() is declared here
foo(123); 
// illegal argument
?

This will produce a message saying an error occurred in functions.php, 
but I want it to tell me that the error occurred in index.php, line 3.
Because if I call foo() many times in a script, it is difficult to find 
out which call that failed.

Is this impossible?

Papp Gyozo wrote:

 try, assert() instead of echo()ing error messages.
 
 assert('is_object($obj)');
 
 and write your error handler code or use mine :)
 or am i missing something?
 
 Papp Gyozo
 - [EMAIL PROTECTED]
 
 - Original Message - 
 From: SafeV [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Thursday, November 22, 2001 4:15 PM
 Subject: [PHP] error handling and __LINE__
 
 
 | Hi,
 | I wonder if there's a way to find the line number of the calling script 
 | from a function, like the error messages PHP generates. An example:
 | 
 | In an included file I have a function and want to do something similar to:
 | 
 | function foo($obj) {
 | if (!is_object($obj)) {
 | echo Error: supplied argument is not an object in ;
 | echo __FILE__ .  line  . __LINE__; 
 | }
 | ...
 | }
 | 
 | But __FILE__ and __LINE__ refers to the current file, ie. the file with 
 | the function in, and not the file where the function is called from.
 | The first one I can solve by using $SCRIPT_NAME, but what about the line 
 | number???
 | 
 | 
 | 
 | -- 
 | PHP General Mailing List (http://www.php.net/)
 | To unsubscribe, e-mail: [EMAIL PROTECTED]
 | For additional commands, e-mail: [EMAIL PROTECTED]
 | To contact the list administrators, e-mail: [EMAIL PROTECTED]
 | 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] error handling and __LINE__

2001-11-22 Thread SafeV

Hi,
I wonder if there's a way to find the line number of the calling script 
from a function, like the error messages PHP generates. An example:

In an included file I have a function and want to do something similar to:

function foo($obj) {
if (!is_object($obj)) {
echo Error: supplied argument is not an object in ;
echo __FILE__ .  line  . __LINE__;
}
...
}

But __FILE__ and __LINE__ refers to the current file, ie. the file with 
the function in, and not the file where the function is called from.
The first one I can solve by using $SCRIPT_NAME, but what about the line 
number???



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Object and reference problem

2001-10-18 Thread SafeV

Yes, thanks, but then I can't pass a string or int as a parameter as 
well, which is what a want.


Neil Kimber wrote:

 You're not passing by reference.
 Change:
 
 function add($child) {
$this-children[] = $child;
 }
 
 to
 
 function add($child) {
$this-children[] = $child;
 }
 
 This should work. When you pass an object as a parameter PHP makes a copy of
 that object as a local instance in your method. So, your original code:
 
 4 $obj2-add(, something else);
 5 $obj1-add($obj2);
 
 would alter $obj2 and store a copy of that altered object in $obj1. But,
 
 5 $obj1-add($obj2);
 4 $obj2-add(, something else);
 
 would store a copy of unaltered $obj2 in $obj1. You'd then alter a different
 instance of $obj2 in the succeeding line.
 By using the suggested altered code at the top of this email, line 5 would
 not pass a copy but would pass a reference to the actual instance of the
 object. Note, you also have to ensure that you store a reference to this guy
 in your array as by default adding items to arrays causes copies to be made.
 So you also need the line:
 
$this-children[] = $child;
 
 Hope this helps.
 
 
 
-Original Message-
From: Brian White [mailto:[EMAIL PROTECTED]]
Sent: 17 October 2001 04:41
To: SafeV; [EMAIL PROTECTED]
Subject: Re: [PHP] Object and reference problem


I think you are going to have to live with it.

Functional overloading only really makes sense in strongly typed
languages, and I bet is a bugger to implement in a name based
scripting language so I don't think you are goign to get it.

What I have sometimes wished for was that all objects and arrays
were passed around as pointers by default, with the ability
to create a copy when required, but that is such a fundamental
change that I doubt if it will happen, and there are probably
goo reasons not to ( have I ever told people how much I like
Python ... )

Maybe you are just going to have to bite the bullet and have
an AddRef method..


At 04:28 17/10/2001 +0200, SafeV wrote:

Someone, have a go at this!

I have encountered a very troublesome problem, which I don't see how to
solve in an elegant way, since PHP doesn't support method overloading.

Suppose my class is, kind of a tree, like:

class A {
   var $children;

   function A() {
   $this-children = array();
   }

   // I want this to accept both objects and strings etc.
   // IE. mixed
   function add($child) {
  $this-children[] = $child;
   }

   function printStuff() {
  foreach ($this-children as $child) {
 if (is_object($child))
$child-printStuff();
 else
   echo $child;
  }
   }
}

Now this is fine:

1 $obj1 = new A();
2 $obj2 = new A();
3 $obj1-add(Something);
4 $obj2-add(, something else);
5 $obj1-add($obj2);
6 $obj1-printStuff();

and prints out something, something else

But if I swap lines 4 and 5 it only prints out something.
Obviously, the add method of $obj1 only receives a copy of $obj2, and
if I try to add something to $obj2 afterwards, even thought it's

supposed

to be hooked with $obj1, it will disappear.

For objects only I could solve this with declaring add() like:
function add($child) {
$this-children[] = $child;
}
So it receives a reference of the object, but then I can't add a string
(fatal error, cannot pass string as reference), or an integer or double,
for that matter! And I really don't want to use different method names!

I don't have full control over the reference stuff in PHP, does anyone
know how I can fix this? Or a workaround?

Thanx!


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-
Brian White
Step Two Designs Pty Ltd - SGML, XML  HTML Consultancy
Phone: +612-93197901
Web:   http://www.steptwo.com.au/
Email: [EMAIL PROTECTED]


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Object and reference problem

2001-10-18 Thread SafeV

Sigh, I guess you're right...
But I think a better solution is to wrap strings in a String object

Thanks for your input!

Brian White wrote:

 I think you are going to have to live with it.
 
 Functional overloading only really makes sense in strongly typed
 languages, and I bet is a bugger to implement in a name based
 scripting language so I don't think you are goign to get it.
 
 What I have sometimes wished for was that all objects and arrays
 were passed around as pointers by default, with the ability
 to create a copy when required, but that is such a fundamental
 change that I doubt if it will happen, and there are probably
 goo reasons not to ( have I ever told people how much I like
 Python ... )
 
 Maybe you are just going to have to bite the bullet and have
 an AddRef method..
 
 
 At 04:28 17/10/2001 +0200, SafeV wrote:
 
 Someone, have a go at this!

 I have encountered a very troublesome problem, which I don't see how 
 to solve in an elegant way, since PHP doesn't support method overloading.

 Suppose my class is, kind of a tree, like:

 class A {
var $children;

function A() {
$this-children = array();
}

// I want this to accept both objects and strings etc.
// IE. mixed
function add($child) {
   $this-children[] = $child;
}

function printStuff() {
   foreach ($this-children as $child) {
  if (is_object($child))
 $child-printStuff();
  else
echo $child;
   }
}
 }

 Now this is fine:

 1 $obj1 = new A();
 2 $obj2 = new A();
 3 $obj1-add(Something);
 4 $obj2-add(, something else);
 5 $obj1-add($obj2);
 6 $obj1-printStuff();

 and prints out something, something else

 But if I swap lines 4 and 5 it only prints out something.
 Obviously, the add method of $obj1 only receives a copy of $obj2, and
 if I try to add something to $obj2 afterwards, even thought it's 
 supposed to be hooked with $obj1, it will disappear.

 For objects only I could solve this with declaring add() like:
 function add($child) {
 $this-children[] = $child;
 }
 So it receives a reference of the object, but then I can't add a 
 string (fatal error, cannot pass string as reference), or an integer 
 or double, for that matter! And I really don't want to use different 
 method names!

 I don't have full control over the reference stuff in PHP, does anyone 
 know how I can fix this? Or a workaround?

 Thanx!


 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 
 -
 Brian White
 Step Two Designs Pty Ltd - SGML, XML  HTML Consultancy
 Phone: +612-93197901
 Web:   http://www.steptwo.com.au/
 Email: [EMAIL PROTECTED]
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] file upload problem

2001-10-18 Thread SafeV

I've run into the same problem, I had to 'chmod 777 images' to be able 
to create dirs or files, which is BAD security!

Brian Aitken wrote:

 Hiya
 
 I promise I won't keep perstering you after this question :-)
 
 My problem is this - I've got a complete system that works perfectly on
 Linux but I've got to set it up on a new server that's running Windows.
 When I try to handle file uploads I get errors (when the same code worked
 perfectly under Linux).
 
 When I try to use mkdir like this:
 
 $name4loc = urlencode($mname);
 $loc = ./images/$name4loc;
 mkdir($loc,0777);
 
 I get the error:
 
 Warning: MkDir failed (Permission denied) in
 D:\Inetpub\wwwroot\HATII\admn\php\moss\mregdone.php on line 98
 
 When I try to copy a file like this:
 
 if (!copy ($test, $test_name))
 
 
   echo(Problem: Unable to copy image. brPlease try again.);
   exit;
  }
 
 I get the error:
 
 Warning: Unable to create 'vinlogo.jpg': Permission denied in
 D:\Inetpub\wwwroot\HATII\admn\php\a2paw\uptestdone.php on line 41
 
 I'm guessing PHP is somehow lacking permission to write to the file system
 but the technicians have tried changing the file permission for the
 directory I'm trying to write to and the same error is given.  We don't know
 what else to do.
 
 Any ideas?
 
 Thanks
 Brian
 
 
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: PDF Download / View

2001-10-18 Thread SafeV

I'm not 100% sure, but try adding one more header:

Header(Content-Disposition: attachment; filename=\ . $filename. \);


Ville Mattila wrote:

 Hello world,
 
 I've made a little script which simply returns a pdf file through it (script file 
called dl.php in the chart-directory):
 
 ?
  $file_size = filesize($filepath);
  Header(Content-Type: application/pdf);
  Header(Content-Length: .$file_size);
 
  readfile($filepath);
 ?
 
 This script works fine when there is Acrobat Reader Browser -plug-in installed to 
users' box so that the PDF File appears into the IE's or Netscapes' normal window. 
But if and when user wants to save the pdf file (which should be allowed), some 
problem appear. In the case that user right-clicks the link to this script and 
selects Save the file as... (or something, I have Finnish version of IE ;) the 
browser thinks that user is downloading chart.html -file! I suppose that same 
phenomenon appears when there is no Acrobat plug-in installed and browser doesn't 
find corresponding action for application/pdf -mime type - it begins to download 
file.
 
 Any suggestions how user can download the file via that script as the file will be 
saved as pdf-file?
 
 Thanks and cheers,
 - Ville
 
 
 .
 Ville Mattila
 Ikaalinen, Finland
 gsm +358-40-8497506
 [EMAIL PROTECTED]
 www.pilotmedia.fi
 
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: Always running script

2001-10-18 Thread SafeV

If you 'set_time_limit(0);' your script won't time out.
But it's probably better to have some other kind of background script to 
run on the server...

Ville Mattila wrote:

 Hi there again,
 
 I was wondering that would it be possible to make a script which is always running? 
Maybe it should be started via console, but there is anyway that maximum execution 
time limit which should be revoke in this case. Any ideas?
 
 - Ville
 
 
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]