php-general Digest 8 Dec 2010 22:50:54 -0000 Issue 7076

Topics (messages 309907 through 309916):

Re: new keyword combined with other things...
        309907 by: Tommy Pham
        309910 by: Paul M Foster
        309912 by: David Harkness
        309914 by: Tommy Pham
        309915 by: Nathan Nobbe

Re: PHP4 to PHP5 migration with E_STRICT
        309908 by: Tommy Pham

Re: newbie basic realm protection - why don't the input usr/pass stick?
        309909 by: Govinda

Re: No errors gets displayed, just a blank page
        309911 by: tedd
        309913 by: Ashley Sheridan

how can one run python script in php
        309916 by: Moses

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Tue, Dec 7, 2010 at 1:55 PM, Paul M Foster <pa...@quillandmouse.com> wrote:
>
> $this->db->select('title')->from('mytable')->where('id', $id)->limit(10,
> 20);
>
> What kind of internal magic they use to make this work, I don't know. I
> haven't examined their internals.
>
> Paul
>
> --
> Paul M. Foster
>

I've never seen the code nor used CodeIgniter but it might be
something like this:

class DB extends Abstraction
{
  private $sqlString;
  private $hasWhere;

  public function select($fields)
  {
    if (is_array($fields)) $this->sqlString = 'select '.implode(',' $fields);
    else $this->sqlString = 'select '.$fields;
    return $this;
  }
  public function from($from)
  {
    $this->sqlString .= ' from '.$from;
    return $this;
  }
  public function where($field, $value, $isAnd = false)
  {
    if ($this->hasWhere)  $this->sqlString .= $isAnd ? ' and ' : ' or ';
    else
    {
      $this->hasWhere = true;
      $this->sqlString .= ' where ';
    }
    $this->sqlString .= $field.' = '.$this->escape($value);
    return $this;
  }
  public function limit($start, $rows)
  {
    $this->sqlString .= " limit {$start}, {$rows}";
    return $this;
  }
  // other methods
}

The only need I see for this is to build the query dynamically...
which should be very rare since all those function calls are
expensive, IMO.

Regards,
Tommy

--- End Message ---
--- Begin Message ---
On Wed, Dec 08, 2010 at 07:14:39AM -0800, Tommy Pham wrote:

> On Tue, Dec 7, 2010 at 1:55 PM, Paul M Foster <pa...@quillandmouse.com>
> wrote:
> >
> > $this->db->select('title')->from('mytable')->where('id', $id)->limit(10,
> > 20);
> >
> > What kind of internal magic they use to make this work, I don't know. I
> > haven't examined their internals.
> >
> > Paul
> >
> > --
> > Paul M. Foster
> >
> 
> I've never seen the code nor used CodeIgniter but it might be
> something like this:

[snip]

> 
> The only need I see for this is to build the query dynamically...
> which should be very rare since all those function calls are
> expensive, IMO.

I agree. My advice for SQL is always to learn SQL rather than use a
bunch of active record functionality. But I'm sure people think I'm just
a curmudgeonly old turd. ;-}

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
On Wed, Dec 8, 2010 at 9:31 AM, Paul M Foster <pa...@quillandmouse.com>wrote:

> I agree. My advice for SQL is always to learn SQL rather than use a
> bunch of active record functionality. But I'm sure people think I'm just
> a curmudgeonly old turd. ;-}
>

Yes, absolutely learn SQL so you understand what's happening under the
covers, AND then use a framework to abstract much of it away. I cannot speak
to ActiveRecord, but ORM frameworks like Hibernate in the Java world save
countless man-hours of work every day, time that can be spent on making
better applications.

On Wed, Dec 8, 2010 at 7:14 AM, Tommy Pham <tommy...@gmail.com> wrote:

> The only need I see for this is to build the query dynamically...
> which should be very rare since all those function calls are
> expensive, IMO.
>

Function calls haven't been expensive since 1992. ;) The cost of running the
SQL query itself will dwarf any function calls made to build the query. The
gains in developer productivity vastly outweigh the small gains to be had by
micro-optimizing away function calls and other abstractions, and developer
time is much more expensive than CPU time.

Start with code that is easy to understand, write, and debug. Measure the
performance if it is too slow, find the slow parts using a profiler, and
optimize them. Nine times out of ten you can gain more by changing your
algorithm than by removing function calls.

David

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: David Harkness [mailto:davi...@highgearmedia.com]
> Sent: Wednesday, December 08, 2010 10:46 AM
> To: Paul M Foster
> Cc: php-gene...@lists.php.net
> Subject: Re: [PHP] new keyword combined with other things...
> 
> On Wed, Dec 8, 2010 at 9:31 AM, Paul M Foster
> <pa...@quillandmouse.com>wrote:
> 
> > I agree. My advice for SQL is always to learn SQL rather than use a
> > bunch of active record functionality. But I'm sure people think I'm
> > just a curmudgeonly old turd. ;-}
> >
> 
> Yes, absolutely learn SQL so you understand what's happening under the
> covers, AND then use a framework to abstract much of it away. I cannot
> speak to ActiveRecord, but ORM frameworks like Hibernate in the Java
> world save countless man-hours of work every day, time that can be spent
> on making better applications.
> 

Last time I checked, there isn't an equivalent of Hibernate for PHP. :)

> On Wed, Dec 8, 2010 at 7:14 AM, Tommy Pham <tommy...@gmail.com>
> wrote:
> 
> > The only need I see for this is to build the query dynamically...
> > which should be very rare since all those function calls are
> > expensive, IMO.
> >
> 
> Function calls haven't been expensive since 1992. ;) The cost of running
the
> SQL query itself will dwarf any function calls made to build the query.
The
> gains in developer productivity vastly outweigh the small gains to be had
by
> micro-optimizing away function calls and other abstractions, and developer
> time is much more expensive than CPU time.

Don't know about that since every little bit adds up and with the lower
power consumption aka 'go green', it's hard to say ;)  As for optimizing, it
should have been considered during the application design process before the
code is written.

Regards,
Tommy

> 
> Start with code that is easy to understand, write, and debug. Measure the
> performance if it is too slow, find the slow parts using a profiler, and
> optimize them. Nine times out of ten you can gain more by changing your
> algorithm than by removing function calls.
> 
> David



--- End Message ---
--- Begin Message ---
On Wed, Dec 8, 2010 at 12:26 PM, Tommy Pham <tommy...@gmail.com> wrote:

> > -----Original Message-----
> > From: David Harkness [mailto:davi...@highgearmedia.com]
> > Sent: Wednesday, December 08, 2010 10:46 AM
> > To: Paul M Foster
> > Cc: php-gene...@lists.php.net
> > Subject: Re: [PHP] new keyword combined with other things...
> >
> > On Wed, Dec 8, 2010 at 9:31 AM, Paul M Foster
> > <pa...@quillandmouse.com>wrote:
> >
> > > I agree. My advice for SQL is always to learn SQL rather than use a
> > > bunch of active record functionality. But I'm sure people think I'm
> > > just a curmudgeonly old turd. ;-}
> > >
> >
> > Yes, absolutely learn SQL so you understand what's happening under the
> > covers, AND then use a framework to abstract much of it away. I cannot
> > speak to ActiveRecord, but ORM frameworks like Hibernate in the Java
> > world save countless man-hours of work every day, time that can be spent
> > on making better applications.
> >
>
> Last time I checked, there isn't an equivalent of Hibernate for PHP. :)


pretty sure doctrine is as close as it gets w/ its DQL

-nathan

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Tom Robinson [mailto:tom.robin...@motec.com.au]
> Sent: Tuesday, December 07, 2010 4:03 PM
> To: php-gene...@lists.php.net
> Subject: [PHP] PHP4 to PHP5 migration with E_STRICT
> 
> Hi,
> 
> I'm migrating a web application written for PHP4 to PHP5. I've turned on
> E_STRICT to have a detailed look at all the code thoroughly. I have a
number
> of 'Notices' and 'Strict Standards' messages appearing now.
> 
> I don't consider myself a PHP guru by any means so I'm seeking help with
> understanding these messages and how to fix the code.
> 
> One of the messages is:
> 
> "PHP Strict Standards:  Only variables should be assigned by reference in"
> 
> This is for a class SPControlPanel with a method
> 
> function getContentTypes(&$db)
>     {
>         $tabledata = array();
> 
>         $sql = "select
>                     contenttype.*
>                 from
>                     contenttype";
> 
>         return $db->queryAll($sql, true);
>     }
> 
> The warning is for this segment of code below which is another method in
> the same class (marked with comment // this line):
> 
> function getCategoryTypes(&$db) {
>         $tabledata = array();
> 
>         $myContentTypes = &SPControlPanel::getContentTypes($db); // this
> line
>         foreach ($myContentTypes as $key => $data) {
>             if ($data['iscategory']) $tabledata[] = $data['contenttype'];
>         }
> 
>         return $tabledata;
>     }
> 
> There are many more methods making assignments in a similar way in this
> class and in other classes throughout the code.
> 
> I'm not sure of the best way to re-code this to resolve the E_STRICT
warning.
> 
> Any help is much appreciated.
> 
> Regards,
> 
> Tom
> 

IIRC, objects are passed by referenced in PHP5.  There's no need to '&' by
the object variable.  Remove the & and do a var_dump and you'll see it
refers the same class object #.

Regards,
Tommy




--- End Message ---
--- Begin Message ---
you script looks (and works) fine. so i dont think the problem is in your script

I found firebug/live http headers firefox addons to be helpful in this situation
see if your client is actually sending "Authorization      Basic" header

Kranthi.
http://goo.gl/e6t3

Kranthi, thanks for looking.. I did find out with the help of the host.. that the issue was because PHP was running in fastcgi mode instead of apache module mode. Now it is behaving as expected.

-Govinda

--- End Message ---
--- Begin Message ---
At 2:07 AM +0100 12/8/10, Rico Secada wrote:
Hi.

What can cause that no parse error gets displayed (blank page/no output
at all) even though error reporting is set to "-1"?

I have run the script through php lint on the console and it comes up
with no errors.

I have run into this problem the last couple of days making debugging a
nightmare.

Anyone with experience in this behavior?

Thanks and best regards

Rico

Rico:

You probably have an error.

So, start with a blank page that contains echo('aaa'); and see if it runs. If it does, then 'aaa' will be printed.

Then start adding your code in small portions and run same until you don't see 'aaa' appear. From there, figure out what portion of your code doesn't work.

That is a "sure fire" way to find all errors.

Cheers,

tedd

--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
On Wed, 2010-12-08 at 13:16 -0500, tedd wrote:

> At 2:07 AM +0100 12/8/10, Rico Secada wrote:
> >Hi.
> >
> >What can cause that no parse error gets displayed (blank page/no output
> >at all) even though error reporting is set to "-1"?
> >
> >I have run the script through php lint on the console and it comes up
> >with no errors.
> >
> >I have run into this problem the last couple of days making debugging a
> >nightmare.
> >
> >Anyone with experience in this behavior?
> >
> >Thanks and best regards
> >
> >Rico
> 
> Rico:
> 
> You probably have an error.
> 
> So, start with a blank page that contains echo('aaa'); and see if it 
> runs. If it does, then 'aaa' will be printed.
> 
> Then start adding your code in small portions and run same until you 
> don't see 'aaa' appear. From there, figure out what portion of your 
> code doesn't work.
> 
> That is a "sure fire" way to find all errors.
> 
> Cheers,
> 
> tedd
> 
> -- 
> -------
> http://sperling.com/
> 


I'd also check any errors logs for this site made by Apache, as that
will tell you where PHP is falling over. If you have access to the whole
server run a 'tail -f' command in a terminal and go to your site again
in the browser, that way, you'll see the new error messages as they come
in.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Hi Everyone,

I am trying to run a python script in php using exec or system command, but
there is
no answer.

musa

--- End Message ---

Reply via email to