Re: [PHP] set_error_handler() fails

2006-05-05 Thread Martin Alterisio \El Hombre Gris\

icy escribió:

chris smith wrote:


What does your code look like?


I just realized that when called a second time, set_error_handler() 
returns my custom error handler but it is never triggered.

Code looks like this:

?php
if (set_error_handler('core_error_handler', E_ALL) === NULL)
echo 'could not set error handlerbr /';

trigger_error('test error');

var_dump(set_error_handler('core_error_handler', E_ALL));

function core_error_handler($errno, $errstr, $errfile, $errline)
{
echo 'error...';
}
?

This gives me the following output:

could not set error handler
Notice: test error in /var/www/.../core.inc.php on line 5
core_error_handler

Have you thought about the fact that you're pointing to a function 
that's not been defined yet when the error is triggered?


And set_error_handler() returns NULL because there isn't a previously 
defined error handler, not because it failed.


Hope this helps.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problem with usort

2006-05-04 Thread Martin Alterisio \El Hombre Gris\

Rabin Vincent escribió:

On 5/4/06, Jon Earle [EMAIL PROTECTED] wrote:

  $ret_val = 0;
  if ($aday == $bday) {$ret_val = 0;}
  else {$ret_val = ($aday  $bday) ? -1 : 1;}
  return ret_val;


You're missing the $ for ret_val on the return line.

PHP thus understands the return value as a string,
ret_val, which would be taken as 0. Since all elements
are now equal, the order of the elements in the array
is undefined.

Rabin

Actually, PHP first looks for a constant named ret_val, then it uses a 
string containing ret_val. So, if there was a constant with that name, 
that value would have been used.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sanity checker?

2006-05-03 Thread Martin Alterisio \El Hombre Gris\

Ezra Nugroho escribió:

Well,

Since my original post failed to generate reasonable feedback, not even
a successful kick at people's funny bone or a flame, let me restate my
question with a story.

Php reduces the barrier to web development quite a bit, such that less
technical people can jump in really easily. In one side, this is great
because it helps the adoption of the language, and more people get to
create their dynamic websites.

The flip to it is that many non-technical people write low quality php
code, which in turn make their code vulnerable and not scalable.

I envision a tool that would audit your php code, and tell you if your
code is good or not, if it has scaling issues, etc, etc. Basically it
tells if your php code is sane or not.

I have a few ideas of how a sane php code should look like, but I
certainly don't know everything. That's the reasons behind my earlier
questions. Basically I am looking for things to check in codes that pose
high running time risks. Or even simpler, I am looking for best
practices, advices, guidelines that you would give to new php
developers.


So here are the questions again:

Does anyone know of any tools to test the sanity of your php code?

If you were to check the sanity of your code, what would you look for?

Any pointers for other resources?


Thank you
Ezra

  
That's something PCs are still not able to do. We still have a long way 
to go before algorithms can simulate consciousness to the level they can 
judge the sanity of a code. For the time being, auditors will have to be 
humans, although they use some tools to make that task easier, mostly 
predefined searches with regular expressions to find common mistakes and 
possible security holes and malicious code. Where I worked some years 
ago they run your code through some awk scripts and shell scripts 
automatically on everything send to production, and after that, they 
auditioned the code in the old fashion.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: no offense to Rasmus... are you kidding me

2006-04-20 Thread Martin Alterisio \El Hombre Gris\



Matt Todd wrote:


There's nothing wrong with staying true to the philosophy at all, I
just think that it may well be detrimental in the end. And that is
what I said in the (toilet)paper, that there will be (emphasis on the
eventuality, not on the present actuality) a time that PHP will become
the old stuff because it did not evolve with the philosophies.
 

It's true that a language that doesn't evolve with the market will die, 
but still you can expect us to follow any new trend because they believe 
it's the way to salvation. Try to think first if the new philosophies 
can be properly applied to this market, if they can bring a proper 
solution to our problems (if not they will become a new problem and we 
don't want that). Anyway, programming languages have proved to live 
longer that one could ever expect. Before attending to PHP's funeral, 
I'm pretty sure we'll be burying another die harder language, like the C 
language, in a very emotional ceremony (I can almost see it, someone 
will cry loudly: I'll miss using your precompiler macros!).



These philosophies are new and I can understand thinking that it's
hype, but it's important to recognize it as legitimate. Agile
Development (and the broader term Web 2.0) is, right now, the bleeding
edge of development, and I and many others see it as the future of
development philosophies.
 

Don't say it's good, prove it! All I can see in Web 2.0 is those guys 
are making more money than us, let's copy them!
Those guys are exploring uncharted area in web development and they're 
more worried in making their software work rather than worrying if the 
philosophy is appropiate or not. Still, marketing rules say no mather 
how unappropiate your company's philosophy is, it's the best. Of course 
they will say Web 2.0 is the best, is what they're doing and they 
don't want anyone to think they aren't giving the clients the best there 
is. And now we have to deal with even crazier request from our clients, 
like making an AJAX application in a week that supports all imaginable 
browsers in the market. They really believe that AJAX is a fucking walk 
in the park! AJAX is a fricking cocktail of death! Bring out the 
spaghetti code and let us feast on an eternal reengeneering cycle!



I'm not saying that Rasmus can't see, but that he will easily choose
to stay with how he sees the forest – understandable as I choose to
stay with what I see, but I think he has a lot invested in his view
and may not open up as easily.
 

Stop blaming the poor guy! He only made a tool he needed and was kind 
enough to share it with the world. If you want to blame someone for what 
direction PHP has taken, blame us! That's the whole point of PHP being 
open source, isn't it? All the current problems in PHP are directly or 
indirectly caused by whining developers and their extravagant requests. 
Magic quotes are bad? Well, teach those bastards to properly quote their 
sql's strings!


You think that currently PHP is being lead to unavoidable doom? By all 
means, be my guest and make PHP++, for all I care. The code it's there.



To Stut:

Honestly, I'd love to see basic variables be objects, as models of
real world data with properties for the data such as a $number-length
or $word-as_array() giving you letters.

 

Have you stop to think what the efficiency cost would be to make 
everything an object? We're already suffering much to avoid the waiting 
2.5 second it's way too much cutline (they say we can't do real time 
applications) and you want to keep adding functionality that will 
deteriorate this? I love the way basic types are handled by PHP, I 
specially love PHP arrays, if you touch them, I fucking kill you!



I know that PHP is a functional language, and secondly, an OO
language, but I think that you can blend these things better and have
the OO brought to the forefront a bit more. Yes, I'm a fan of OO, but
I know that many people aren't and don't use PHP's OO (and don't when
it's appropriate). But I know you can integrate OO without having to
force the functional programmers to give up their way.

 

Have you been attending to your CS lessons? PHP is an *IMPERATIVE* 
language, and secondly, that the language provides OOP features doesn't 
make it an OO language. Maybe you have chosen your language wrongly, you 
should try JSP or any other Java based web server technology.


PS: I think you have the terms wrong. What you're calling functional 
programming may be what is usually known as procedural programming.



This is just ONE thing that could make PHP better and allow for more
modern philosophical development. Particularly, I would like to see
more creativity. Sure, PHP's moving fast, but with our big things
being Unicode support and removing globals and safe mode, I think that
we could be a little more innovative for PHP6.

Again, it's not behind the times right now, but the times are changing
and I'd like to see PHP change with them.

M.T.
 

I won't deny times are 

Re: [PHP] session

2006-04-20 Thread Martin Alterisio \El Hombre Gris\

It's really that hard to read the whole manual page about session_destroy()?

Quoting the php manual:
In order to kill the session altogether, like to log the user out, the 
session id must also be unset. If a cookie is used to propagate the 
session id (default behavior), then the session cookie must be deleted. 
setcookie()  may be used for that.


In other words session_destroy() is not enough to kill a session.

PS: I just checked the portuguese version of the manual, it seems to be 
outdated (I don't know portuguese but from the examples given and some 
deductive reasoning I'm sure it's either a translation of an old version 
of the manual or a bad translation). If you understand english, rely on 
the english version.


João Cândido de Souza Neto wrote:


Hi everyone.

I hope someone here can help me.

When i start a session in a php page, this session receives an unique id.

If you think about this, if i call a session_destroy() in any page and in
the other paga call a session_start() again, it'll receive other unique id.
But it isn't working. Everything above has been executed but the session
id's always the same.

It can be any config var in php.ini?

Thanks for tips.

 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP error log

2006-04-20 Thread Martin Alterisio \El Hombre Gris\

Please, explain how are you logging the errors.

Weber Sites LTD wrote:


Hi

I'm using PHP 4.4.0 (cli) and all of the errors / warnings are written to
file.
I can see all of the direct errors but when I have an error inside an
include
file the script fails and the error is not shown in the log. I have to
guess 
Where the error is.


Any idea what I'm missing.

Thanks
Berber

 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_destroy

2006-04-19 Thread Martin Alterisio \El Hombre Gris\
It doesn't matter, PHP decides automatically which is the best method to 
make a session persist. If it founds that the client allows cookies, 
cookies are used. If such method is not available, the session id is 
writen to every url through an output buffer with an url rewriting 
filter. There was another method before using the url rewriting but I 
forgot, check the manual.


Shannon Doyle wrote:


That's just it,

I am not setting a session cookie.

Just starting a session with the following :-


session_name(XPCSESS);
session_start();
$sessID = session_id();



-Original Message-
From: Martin Alterisio El Hombre Gris [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, 19 April 2006 12:36 PM

To: Peter Hoskin
Cc: Shannon Doyle; php-general@lists.php.net
Subject: Re: [PHP] session_destroy

That's exactly what the manual says.
session_destroy() doesñ't clean the session cookie (if one is used), 
that's probably why your session persists.


Peter Hoskin wrote:

 

I've also had this issue from time to time. Used the following to 
destroy it under all circumstances.


  if (isset($_COOKIE[session_name()])) {
  setcookie(session_name(), '', time()-42000, '/');
  }
  session_destroy();

Shannon Doyle wrote:

   


Hi People,

Trying to get a session to destroy correctly, however the darn thing 
just
refuses to destroy. I call the following in a separate webpage in a 
effort

to destroy the session, only to find that the session still persists.

?php
session_start();
session_unset();
session_destroy();
Header(Location: index.php);
?


Any help would be appreciated.

Cheers,

Shannon

 
 

   



 



Re: [PHP] programming contests as a way of finding/evaluating offshore talent...

2006-04-19 Thread Martin Alterisio \El Hombre Gris\

This is just my personal opinion on the subject.

I don't believe nowadays programming contests are of any worth when 
judging a developer's talent, at least not what I expect from a coder. 
These contests usually prove that an a coder can pull out an development 
as an individual, but from looking at the code, and the way they code, I 
realize that they aren't fit for an enviroment where working as a team 
is a must, at least that's the kind of coding I don't want to see in a 
project where I could be working.


I haven't seen yet a contest where code which is written in a readable 
and understandable way earns more points. If a coder does his job faster 
than others but he's the only one who can understand the code, we'll 
have a problem when the client requires a new feature and he's not 
longer on our team. I would choose the one who takes his time but thinks 
carefully ahead and takes into account who will be using the code he's 
writting. If he is also good with documentation I'll even handcuff him 
to his desk and do anything to keep him in the team.


bruce wrote:


hi..

i'm looking for opinions on the worth of programming contests as a way of
judging the talent of potential software developers...

any thoughts/pros/cons would be appreciated..

and yeah.. i know this is a little off topic.. but some of us here deal with
these issues.. if you know of a better email list for this kind of question,
let me know, and i'll move it to there..

thanks in advance!

-bruce

 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Pushing PHP Into The Web 2.0 Generation

2006-04-18 Thread Martin Alterisio \El Hombre Gris\
Just what I needed today, another guy trying to find solutions when he 
doesn't even comprehend what the real problem is.

A complete waste of my time.

James Crane wrote:


I've written a short paper on the future of PHP and I'd appreciate it
if you folks would take a look at it and exchange your thoughts with
me.

http://www.maraby.com/papers/pushing_php_into_the_web_20_generation

Don't be too skeptical. ;)

Cheers!

M.T.

 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_destroy

2006-04-18 Thread Martin Alterisio \El Hombre Gris\

That's exactly what the manual says.
session_destroy() doesñ't clean the session cookie (if one is used), 
that's probably why your session persists.


Peter Hoskin wrote:

I've also had this issue from time to time. Used the following to 
destroy it under all circumstances.


   if (isset($_COOKIE[session_name()])) {
   setcookie(session_name(), '', time()-42000, '/');
   }
   session_destroy();

Shannon Doyle wrote:


Hi People,

Trying to get a session to destroy correctly, however the darn thing 
just
refuses to destroy. I call the following in a separate webpage in a 
effort

to destroy the session, only to find that the session still persists.

?php
session_start();
session_unset();
session_destroy();
Header(Location: index.php);
?


Any help would be appreciated.

Cheers,

Shannon

  





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How can I see where my script wasting time?

2006-04-17 Thread Martin Alterisio \El Hombre Gris\
Use the EXPLAIN sql command to check what your queries are really doing, 
you'll have to read the manual for the database you're using to figure 
out the information returned by this command.


[EMAIL PROTECTED] wrote:


Hi to all!

I was developing one site with fake records in DB. Now, I put it live whit
real records. The site is running ok, but it's painfully slow. Even for
grabbing an order from DB and showing it on screen, from 1-2 sec (while
developing) went to almost 10-15 sec?!? No, of records for orders is a
little bit over 200,000 - what is not so much.

I'm assuming that the problem is not in the script than in the way I built
queries.

My question is how can I check what's taking so long in execution of the
script/query?
Where to start with improving the script?

Thanks for any help.

-afan

 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] internationalization of web site

2006-04-12 Thread Martin Alterisio \El Hombre Gris\
Ussually, the browsers send a header with information about the language 
preferences of the user.

This header is HTTP_ACCEPT_LANGUAGE.
You can retrieve its value in PHP through the array $_SERVER:
$_SERVER['HTTP_ACCEPT_LANGUAGE']

Here you can find about the format of this header:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4

Alain Roger wrote:


Hi,

Sorry to send this email on both mailing lists but as i suppose that both
are concerned by it, i did.

i would like to make my web site tune to user language.
for that i was thinking to create some XML files where all words can be
found and based on the icon (country flag) that user clicked, i will load a
specific XML file to tune my PHP pages.

i know from Java exprience that it exists also another possibility via
browser setup for preference in language, but i do not know how it works in
PHP.

please, could you give me some tips, helps, or tutorial for such request ?

thanks a lot,
Alain

 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function by reference

2006-04-11 Thread Martin Alterisio \El Hombre Gris\
Well, it was a bad example to begin with, first of all max() is already 
defined in php, I should at least checked that before posting. Second, I 
forgot PHP (the Zend engine) has an interesting way of handling 
variables, when you copy assign a var or pass it as an argument of a 
function, a real copy is not made but a reference. When you modify the 
reference, an actual copy is made before the modification. What's 
happening with the function you posted is that the variables are not 
passed by copy but by reference, that's why it works. Anyway, this is 
due to conditions on the way PHP (the Zend engine) handles its internal, 
you shouldn't rely on this in your code.


http://www.zend.com/zend/art/ref-count.php

tedd wrote:

The ampersand before the function name indicates that the function 
returns a reference instead of a copy of the variable, for example:


?php
  function max($var1, $var2) {
if ($var1  $var2) return $var1;
else return $var2;
  }

  $global1 = 10;
  $global2 = 9;
  $maxglobal = max($global1, $global2);
  $maxglobal++;
  echo $global1;
  //this will print 11 since $maxglobal is a reference to $global1
?



It's going to hurt thinking about that.  :-)

But that produces the same results as:

?php
  function max($var1, $var2) {
if ($var1  $var2) return $var1;
else return $var2;
  }

  $global1 = 10;
  $global2 = 9;
  $maxglobal = max($global1, $global2);
  $maxglobal++;
  echo $global1;
  //this will print 11 since $maxglobal is a reference to $global1
?

Note the absence ampersands in the function, but an ampersand remains 
in the assignment:


Thanks.

tedd


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Martin Alterisio \El Hombre Gris\
Maybe it's too late to say this, but if your real problem is that you 
don't want the function reading
the rss feed to block the rest of your page, you can always put the 
output of the reading of the feed

on a separate page, and include this through an iframe.

darren kirby wrote:


Hello all,

My website uses simpleXML to print the headlines from a few different RSS 
feeds. The problem is that sometimes the remote feed is unavailable if there 
are problems with the remote site, and the result is that I must wait for 30 
seconds or so until the HTTP timeout occurs, delaying the rendering of my 
site.


So far, I have moved the code that grabs the RSS feeds to the bottom of my 
page, so that the main page content is rendered first, but this is only a 
partial solution.


Is there a way to give the simplexml_load_file() a 5 second timeout before 
giving up and moving on? 


Here is my function:

function getFeed($remote) {
   if (!$xml = simplexml_load_file($remote)) {
   print Feed unavailable;
   return;
   }
   print ul\n;
   foreach ($xml-channel-item as $item) {
   $cleaned = str_replace(, amp;, $item-link); 
   print lia href='$cleaned'$item-title/a/li\n;

   }
   print /ul\n;
}

PHP 5.1.2 on Linux.
thanks,
-d
 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php