Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
> On Tue, 2007-10-09 at 21:37 -0400, Nathan Nobbe wrote:
> >
> > does a lawn mower not have blades; and gas and a control panel; does it
> not
> > have
> > wheels?  my object modeling of a lawn mower would certainly have these
> > things;
> > and most likely i would mark components of the engine as private.
> > and what does a lawn mower cut anyway; grass; i thought that was it.  so
> if
> > there
> > was no grass could there still be an algorithm to cut it?
> > i say grass is part of the grass-cutting algorithm.
>
> Well it helps to refine the algorithm, but let's say we use fingers
> instead as our measure... I'm sure we would find that we could cut grass
> also >:)


good point.
the lawn mower is still consistent of its own parts and they
comprise its implementation.

-nathan


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Robert Cummings
On Tue, 2007-10-09 at 21:37 -0400, Nathan Nobbe wrote:
>
> does a lawn mower not have blades; and gas and a control panel; does it not
> have
> wheels?  my object modeling of a lawn mower would certainly have these
> things;
> and most likely i would mark components of the engine as private.
> and what does a lawn mower cut anyway; grass; i thought that was it.  so if
> there
> was no grass could there still be an algorithm to cut it?
> i say grass is part of the grass-cutting algorithm.

Well it helps to refine the algorithm, but let's say we use fingers
instead as our measure... I'm sure we would find that we could cut grass
also >:)

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Larry Garfield <[EMAIL PROTECTED]> wrote:
>
> On Tuesday 09 October 2007, Tony Marston wrote:
> Here's a better reason to not bother learning PHP 4-style OOP.  You have
> less
> than a year until running PHP 4 at all is considered an unsupported
> security
> risk.  Don't waste your time, since PHP 5 OOP IS different, because
> reference
> handling changed drastically which means what is "fast and easy" in PHP 4
> OOP
> and what is "fast and easy" in PHP 5 OOP is hugely different.


which i mentioned early on in the conversation; we got sidetracked on the
argument
about encapsulation for a while.

> > if  you read that one chapter i recommended you will see; acquiring the
> > > behavior of the parent is not always desirable.
> >
> > Then why inherit from the parent in the first place? Or why not create a
> > method in the subclass which overrides the method in the superclass,
> thus
> > changing the behaviour to what you prefer? I certainly don't need
> > interfaces to do that.
>
> Because I want to syntactically guarantee the existence of certain methods
> so
> that I can reliably call functionality on them.  Call-and-pray is an
> unreliable methodology.  Yes, that is syntactic sugar.  See above.
>
> Can we stop with the pissing contest now?


ive been sitting w/ my opinion about php4 for a while now; what can i say; i
had
to get it out and hear the opinion of people on the list.
if anything i have learned some things and gotten insight to viewpoints i
didnt
realize existed.  i hope i have been able to contribute something to someone
amidst all the arguing.

-nathan


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Larry Garfield <[EMAIL PROTECTED]> wrote:
>
> On Tuesday 09 October 2007, Robert Cummings wrote:
>
> > $sucker = new TryToViolateEncapsulation();
> > $sucker = (array)$sucker;
> >
> > $keys = array_keys( $sucker );
> > $sucker[reset( $keys )] = 500;
> >
> > $sucker = serialize( (object)$sucker );
> > $sucker = 'O:25:"TryToViolateEncapsulation"'.substr( $sucker, 14 );
> > $sucker = unserialize( $sucker );
> >
> > print_r( $sucker );
> >
> >
> >
> > Maybe next time you'll have a challenge for me ;) And don't whine about
> > how I achieved what I did.
> >
> > Cheers,
> > Rob.
>
> I've never actually thought of doing it that way, but I must say I find it
> an
> amusing method. :-)


i new rob would come up w/ something otherwise he wouldnt have made the
offer.
i tried to override the __sleep method to throw an exception but it had no
effect;
rob really knows php well.

That said, I stand by my earlier comment.  Never use private
> variables.  Ever.
> Use public or protected, but never private.  Private makes them
> un-extensible
> to child classes.  That's just flat out rude.


right; protected is only for variables that the child class would need
access to;
even children dont need access to all of their parents details.
i say; mark all member variables private and reduce the access as need be.

And really, there's FAR more interesting and useful pieces to OOP, PHP's
> style
> or otherwise, than PPP.  Interfaces are useful.  Being able to pass
> objects
> around to each other without performance or references dying is
> useful.  And
> SPL is just plain cool. :-)


yes; SPL is really nice; though some more documentation would be great.
the articles online mostly cover basic usage examples.

-nathan


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Guillaume Theoret <[EMAIL PROTECTED]> wrote:
>
> On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
> >
> > ""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> > > On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
> > >>
> > >>
> > >> ""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message
> > >> news:[EMAIL PROTECTED]
> > >> > On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> > >> >>
> > >> >> Why would I use an interface? :)
> > >> >
> > >> > because inheritance is not always optimal.
> > >>
> > >> I have never found a prolem when using an interface was the only
> > >> solution,
> > >> or even ANY kind of solution. The fact that your designs need it
> speaks
> > >> volumes of the problems with your designs.
> > >
> > > im not the one whose been defending my designs  in this conversation;
> you
> > > are.
> >
> > But you are the one who keeps saying that your approach, where all
> member
> > variables are hidden, is far superior. I'm just saying that I do share
> that
> > opinion.
> >
> > > there are plenty of situations where the interface is the more elegant
> > > approach, thats why its here; and thats why it was added in php5.
> > >
> > >> There's your problem, then. You are wasting your time trying to
> implement
> > >> fancy design patterns just because design patterns are supposed to be
> > >> "cool".
> > >
> > > i dont recall reading any suggestions to use design patterns because
> they
> > > are cool.
> >
> > But you are the one who pointed out that interfaces are used in design
> > patterns, therefore they *must* be OK. I am saying that I have never
> seen
> > any advantages from using interfaces, and I don't waste my time with
> design
> > patterns.
> >
> > > infact the advice ive read is to only use them when they make sense.
> >
> > My point is that interfaces do not make anysense to me at all. I can
> access
> > all my class methods without them, so what benefit do they give?
> >
> > > Loader class, Controller Base class, Front Controller - I have none
> > >> of that crap in my code, so I don't encounter the problems you have.
> When
> > >> I
> > >> see code like "$this->load->library('email') " I just thank my lucky
> > >> stars
> > >> that I don't have to maintain it. I think some serious refactoring is
> > >> long
> > >> overdue.
> > >
> > > id have to say code igniter is quite a bit more popular than radicore.
> > > maybe youre the one who has some refactoring to do.
> > >
> > > Perhaps you are trying to implement something from another language
> and
> > >> expecting PHP to be just like that other language, which is always a
> > >> stupid
> > >> mistake. PHP is different, therefore the solution will be different.
> I
> > >> suggest you learn how PHP works and design accordingly, and stop
> trying
> > >> to
> > >> force it into emulating another language.
> > >
> > >
> > > well php has certainly gotten its influence from a number of other
> > > languages.
> > > where do you think the additional features in php5 got their
> inspiration
> > > from?
> >
> > Some of those features were implemented just because some a*sholes who
> are
> > more familiar with other languages keep saying "I can do so-and-so in
> > language X, and I want to do exactly the same thing in PHP". Language X
> has
> > interfaces, so PHP *must* have interfaces, Why? What purpose do they
> serve?
> > What benefits do they bring?
> >
> > > btw;
> > > heres the definition of implement from dictionary.com
> > >
> > > im·ple·ment
> > > <
> https://secure.reference.com/premium/login.html?rd=2&u=http%3A%2F%2Fdictionary.reference.com%2Fbrowse%2Fimplementation
> >
> > >  /n. '?mpl?m?nt; v. '?mpl??m?nt, -m?nt/ Pronunciation Key - Show
> Spelled
> > > Pronunciation[n. *im*-pl*uh*-m*uh*nt; v. *im*-pl*uh*-ment, -m*uh*nt]
> > > Pronunciation
> > > Key - Show IPA Pronunciation -noun 1.any article used in some
> activity,
> > > esp.
> > > an instrument, tool, or utensil: agricultural implements.
> > > notice the use of article; ie data; ie; you are wrong about member
> > > variables
> > > not being part of a classes implementation.
> > > if a variable local to a function can be considered part of its
> > > implementation; then a variable local to a class can be
> > > considered part of its implementation; its that simple.
> >
> > Implementation is still an activity or a procedure. A lawnmower is a
> tool
> > which implements lawnmowing, and it acts upon a lawn. However, the lawn
> is
> > not part of the implementation, it is the subject of the implementation.
> An
> > object may contain both variables and operations, but the data is not
> part
> > of those operations, it is the subject of those operations.
> >
> > --
> > Tony Marston
> > http://www.tonymarston.net
> > http://www.radicore.org
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> In response to:
>
> > My point is that interfaces do not make anyse

Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>
>
> ""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
> >>
> >> There's your problem, then. You are wasting your time trying to
> implement
> >> fancy design patterns just because design patterns are supposed to be
> >> "cool".  Loader class, Controller Base class, Front Controller - I have
> >> none
> >> of that crap in my code, so I don't encounter the problems you have.
> >>
> >
> > your site talks about the use of mvc in radicore so we can assume youre
> > using at least one design pattern;
>
> When I say that I do not use design patterns I mean that I do not try to
> implemet as many design patterns as possible,


i never suggested any one do that nor did i suggest that i do that.

and I certainly do not litter
> my conversations with this pattern or that pattern.


then  you failed to grasp one of the most important concepts about design
patterns.
they provide a common vocabulary to allow designers to talk about
implementing
systems at a high level without having to waste time talking about specific
details.

In the whole of my
> career there have only ever been two patterns that I have read about and
> subsequently sought to implement, and thoose are the Three Tier
> Architecture
> and the Singleton. The fact that my framework contains an example of MVC
> is
> pure coincidence. It just happened that way. It was only after someone
> else
> looked at my code and said "You've implemented the MVC pattern" that I
> read
> about it and discovered that it was a perfect match. I certainly did not
> read about MVC and then try to implement it.


that is very common.  many if not most people implement patterns all the
time and
dont realize it.  one benefit of patterns is people can communicate at the
pattern
level.  recognition is powerful as well; if you happen to see a pattern when
you are
working out a design; the pieces just fall into place; or at least you have
a road map.

> and if radicore has a single point of entry you
> > are using a front controller.
>
> I do not have a single point entry. Each page has its own controller, so I
> have hundreds of page controllers. A single front controller is something
> that is used in compiled languages.


its also used heavily in php; take a look at code igniter for a first
example.

> might want to knock the dust off the old design pattern books just to jog
> > your memory:)
>
> I've put my books of design patterns on the top shelf where they shall
> remain untouched as they contain nothing of use to me. They may give hints
> to novices, but I am no longer a novice. I no longer need training wheels
> on
> my bicycle, so why do I need books on design patterns?


ill be honest; i like what youve done w/ xsl, you even taught me some
things;
but when it comes to oop; well i think you should get the books back down
from the top shelf.

-nathan


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>
>
> ""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
> >>
> >>
> >> ""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message
> >> news:[EMAIL PROTECTED]
> >> > On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> >> >>
> >> >> Why would I use an interface? :)
> >> >
> >> > because inheritance is not always optimal.
> >>
> >> I have never found a prolem when using an interface was the only
> >> solution,
> >> or even ANY kind of solution. The fact that your designs need it speaks
> >> volumes of the problems with your designs.
> >
> > im not the one whose been defending my designs  in this conversation;
> you
> > are.
>
> But you are the one who keeps saying that your approach, where all member
> variables are hidden, is far superior. I'm just saying that I do share
> that
> opinion.


fine; lets agree to disagree on that point.

> there are plenty of situations where the interface is the more elegant
> > approach, thats why its here; and thats why it was added in php5.
> >
> >> There's your problem, then. You are wasting your time trying to
> implement
> >> fancy design patterns just because design patterns are supposed to be
> >> "cool".
> >
> > i dont recall reading any suggestions to use design patterns because
> they
> > are cool.
>
> But you are the one who pointed out that interfaces are used in design
> patterns, therefore they *must* be OK. I am saying that I have never seen
> any advantages from using interfaces, and I don't waste my time with
> design
> patterns.


no; i stated interfaces offer an alternate mechanism to realize
polymorphism.
i brought design patterns in when i suggested a book that would illustrate
by
example how interfaces can be used and when they are a better choice than
inheritance.

> infact the advice ive read is to only use them when they make sense.
>
> My point is that interfaces do not make anysense to me at all. I can
> access
> all my class methods without them, so what benefit do they give?


if you just read the one chapter im sure they would make sense; they offer
polymorphism w/o the cost of the parent behavior.

> Loader class, Controller Base class, Front Controller - I have none
> >> of that crap in my code, so I don't encounter the problems you have.
> When
> >> I
> >> see code like "$this->load->library('email') " I just thank my lucky
> >> stars
> >> that I don't have to maintain it. I think some serious refactoring is
> >> long
> >> overdue.
> >
> > id have to say code igniter is quite a bit more popular than radicore.
> > maybe youre the one who has some refactoring to do.
> >
> > Perhaps you are trying to implement something from another language and
> >> expecting PHP to be just like that other language, which is always a
> >> stupid
> >> mistake. PHP is different, therefore the solution will be different. I
> >> suggest you learn how PHP works and design accordingly, and stop trying
> >> to
> >> force it into emulating another language.
> >
> >
> > well php has certainly gotten its influence from a number of other
> > languages.
> > where do you think the additional features in php5 got their inspiration
> > from?
>
> Some of those features were implemented just because some a*sholes who are
> more familiar with other languages keep saying "I can do so-and-so in
> language X, and I want to do exactly the same thing in PHP". Language X
> has
> interfaces, so PHP *must* have interfaces, Why?


youre probly right; if i were to guess id say the interface keyword was
borrowed from
java; im sure .net ripped it off of java too.

What purpose do they serve?


they offer an additional polymorphic mechanism.

What benefits do they bring?


if you havent noticed a class can implement any number of interfaces; it can
only
extend a single class.  this means that the same class  could potentially be
used
polymorphically in several scenarios.
part of the problem w/ inheritance is you can only put methods in the
superclass that
all the children will absolutely need.  otherwise that behavior will be
available in the
child classes and that can be bad news.  the bottom line is; if behavior is
changing
across all subclasses; it is not beneficial to have it in the superclass;
but if a method
will say, still be in many of the children it is desirable to still indicate
they are similar;
in comes the interface to save the day.

> btw;
> > heres the definition of implement from dictionary.com
> >
> > im·ple·ment
> > <
> https://secure.reference.com/premium/login.html?rd=2&u=http%3A%2F%2Fdictionary.reference.com%2Fbrowse%2Fimplementation
> >
> >  /n. '?mpl?m?nt; v. '?mpl??m?nt, -m?nt/ Pronunciation Key - Show Spelled
> > Pronunciation[n. *im*-pl*uh*-m*uh*nt; v. *im*-pl*uh*-ment, -m*uh*nt]
> > Pronunciation
> > Key - Show IPA Pronunciation -noun 1.any article used in some activity,
> > esp.
> > an instrument, tool, or utensil: agricultural i

Re: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Jim Lucas

Jay Blanchard wrote:

[snip]
what is it suppose to return if it cannot find records that the exact
total do not match the total 
you are looking for?  should it return nothing?

[/snip]

Correct. It should say that there are no records that generate a match. 



Ok, so based off what you were asking for, here is a function that I 
think does what you are looking to do.


So, test for false on the returned value and if it is false, the 
function could not find any matches that together would total the amount 
you are asking for. Otherwise, it returns the array of items that will 
total the amount that you are trying to match.


Let me know if it works for you.

 $id, 'value' => round($value, 
2));
$currentValue   += round($value, 2);

if ( round($currentValue, 2) > round($total, 2) ) {
$currentValue -= round($value, 2);
array_pop($items);
continue;
}

if ( round($currentValue, 2) == round($total, 2) ) {
$stack = array();
foreach ($items AS $id => $val) {
if ( in_array($val['id'], $stack) ) {
unset($items[$id]);
} else {
$stack[] = $val['id'];
}
}
return $items;
}

		if ( ( $new = getTotal(round($total, 2), array_slice($values, 1), 
round($currentValue, 2)) ) === false ) {

$currentValue -= round($value, 2);
array_pop($items);
} else {
$items = array_merge($items, $new);
}
}
$tv = 0;
foreach ( $items AS $tmp_value ) {
$tv += round($tmp_value, 2);
}
if ( round($tv, 2) != round($total, 2) ) {
return false;
}
$testing = array();
foreach ( $items AS $row ) {
$testing[$row['id']] = $row['value'];
}
return $testing;
}

$values[] = array(1,3.98);
$values[] = array(2,9.77);
$values[] = array(3,3.76);
$values[] = array(4,4.13);
$values[] = array(5,7.86);
$values[] = array(6,1.45);
$values[] = array(7,12.87);
$values[] = array(8,10.01);
$values[] = array(9,0.88);

var_dump(getTotal(10.22, $values, $value));

?>

my results are

array(4) {
  [0]=>
  array(2) {
["id"]=>
int(3)
["value"]=>
float(3.76)
  }
  [1]=>
  array(2) {
["id"]=>
int(4)
["value"]=>
float(4.13)
  }
  [2]=>
  array(2) {
["id"]=>
int(6)
["value"]=>
float(1.45)
  }
  [3]=>
  array(2) {
["id"]=>
int(9)
["value"]=>
float(0.88)
  }
}



--
Jim Lucas


"Perseverance is not a long race;
it is many short races one after the other"

Walter Elliot



"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Larry Garfield
On Tuesday 09 October 2007, Tony Marston wrote:

> I have bought and read several books on design patterns without being
> impressed. I have seen countless examples of how particular design patterns
> can be implemented, and I am even more unimpressed. Unless you can explain,
> simply and with simple examples, of things that can ONLY be achieved
> through the use of interfaces then I will continue to say tha they are a
> waste of time.

Classic OOP (C++/PHP/Java, etc.) is, really, an extension on top of procedural 
programming.  Nothing that you do with objects couldn't be done without them.  
They are equally expressive.  

OOP is just syntactic sugar to make writing certain logical structures easier 
(less code, more readable code, code that's harder, but not impossible, for 
someone else to break, etc.).  There is absolutely nothing that can ONLY be 
achieved through, for instance, interfaces.  It's just that interfaces make 
it a hell of a lot easier to solve certain problems than doing everything 
with non-dynamic functions.  

Anything you can do with functions you can also do with GOTO statements.  
functions are just syntactic sugar to make writing logical structures easier.  
Until you can explain, with examples, some problem that can ONLY be solved 
through the use of functions I will continue to say that they are a waste of 
time.

Anything that you can do in PHP you could also do in assembler.  PHP is just 
syntactic sugar to make writing logical structures easier.  Until you can 
explain, with examples, some problem that can ONLY be solved through the use 
of PHP I will continue to say that it is a waste of time.

Yes, I am making fun of you for a piss-stupid Luddite argument. :-)

> *My* definition of encapsulation is *the* definition of encapsulation as it
> was originally intended. The fact that other smart arse numbskulls have
> corrupted it with their own stupid embellishments is something which I
> choose to ignore.

*My* definition of dark green is *the* definition as it was originally 
intended.  The fact that other smart-ass numbskulls have corrupted it with 
their own stupid saturation embellishments is something which I choose to 
ignore.

(Yes, I am making fun of you again.)

> > but  you admit, the php5 construct is better and  therefore strengthen my
> > initial argument, which was, if php5 is better and php4 is deprecated;
> > why bother
> > w/ php4.
>
> Your statement was that it would be absolutely pointless trying to learn
> OOP with PHP 4 which implies that it is not possible to write object
> oriented programs wth PHP 4 at all. That is absolute crap as PHP 4 provides
> ALL the basic necessities for OOP, which are encapsulation, inheritance and
> polyorphism.

Here's a better reason to not bother learning PHP 4-style OOP.  You have less 
than a year until running PHP 4 at all is considered an unsupported security 
risk.  Don't waste your time, since PHP 5 OOP IS different, because reference 
handling changed drastically which means what is "fast and easy" in PHP 4 OOP 
and what is "fast and easy" in PHP 5 OOP is hugely different.

> > if  you read that one chapter i recommended you will see; acquiring the
> > behavior of the parent is not always desirable.
>
> Then why inherit from the parent in the first place? Or why not create a
> method in the subclass which overrides the method in the superclass, thus
> changing the behaviour to what you prefer? I certainly don't need
> interfaces to do that.

Because I want to syntactically guarantee the existence of certain methods so 
that I can reliably call functionality on them.  Call-and-pray is an 
unreliable methodology.  Yes, that is syntactic sugar.  See above.

Can we stop with the pissing contest now?

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Larry Garfield
On Tuesday 09 October 2007, Robert Cummings wrote:

> $sucker = new TryToViolateEncapsulation();
> $sucker = (array)$sucker;
>
> $keys = array_keys( $sucker );
> $sucker[reset( $keys )] = 500;
>
> $sucker = serialize( (object)$sucker );
> $sucker = 'O:25:"TryToViolateEncapsulation"'.substr( $sucker, 14 );
> $sucker = unserialize( $sucker );
>
> print_r( $sucker );
>
>
>
> Maybe next time you'll have a challenge for me ;) And don't whine about
> how I achieved what I did.
>
> Cheers,
> Rob.

I've never actually thought of doing it that way, but I must say I find it an 
amusing method. :-)

That said, I stand by my earlier comment.  Never use private variables.  Ever.  
Use public or protected, but never private.  Private makes them un-extensible 
to child classes.  That's just flat out rude.

And really, there's FAR more interesting and useful pieces to OOP, PHP's style 
or otherwise, than PPP.  Interfaces are useful.  Being able to pass objects 
around to each other without performance or references dying is useful.  And 
SPL is just plain cool. :-)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Guillaume Theoret
On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>
> ""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
> >>
> >>
> >> ""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message
> >> news:[EMAIL PROTECTED]
> >> > On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> >> >>
> >> >> Why would I use an interface? :)
> >> >
> >> > because inheritance is not always optimal.
> >>
> >> I have never found a prolem when using an interface was the only
> >> solution,
> >> or even ANY kind of solution. The fact that your designs need it speaks
> >> volumes of the problems with your designs.
> >
> > im not the one whose been defending my designs  in this conversation; you
> > are.
>
> But you are the one who keeps saying that your approach, where all member
> variables are hidden, is far superior. I'm just saying that I do share that
> opinion.
>
> > there are plenty of situations where the interface is the more elegant
> > approach, thats why its here; and thats why it was added in php5.
> >
> >> There's your problem, then. You are wasting your time trying to implement
> >> fancy design patterns just because design patterns are supposed to be
> >> "cool".
> >
> > i dont recall reading any suggestions to use design patterns because they
> > are cool.
>
> But you are the one who pointed out that interfaces are used in design
> patterns, therefore they *must* be OK. I am saying that I have never seen
> any advantages from using interfaces, and I don't waste my time with design
> patterns.
>
> > infact the advice ive read is to only use them when they make sense.
>
> My point is that interfaces do not make anysense to me at all. I can access
> all my class methods without them, so what benefit do they give?
>
> > Loader class, Controller Base class, Front Controller - I have none
> >> of that crap in my code, so I don't encounter the problems you have. When
> >> I
> >> see code like "$this->load->library('email') " I just thank my lucky
> >> stars
> >> that I don't have to maintain it. I think some serious refactoring is
> >> long
> >> overdue.
> >
> > id have to say code igniter is quite a bit more popular than radicore.
> > maybe youre the one who has some refactoring to do.
> >
> > Perhaps you are trying to implement something from another language and
> >> expecting PHP to be just like that other language, which is always a
> >> stupid
> >> mistake. PHP is different, therefore the solution will be different. I
> >> suggest you learn how PHP works and design accordingly, and stop trying
> >> to
> >> force it into emulating another language.
> >
> >
> > well php has certainly gotten its influence from a number of other
> > languages.
> > where do you think the additional features in php5 got their inspiration
> > from?
>
> Some of those features were implemented just because some a*sholes who are
> more familiar with other languages keep saying "I can do so-and-so in
> language X, and I want to do exactly the same thing in PHP". Language X has
> interfaces, so PHP *must* have interfaces, Why? What purpose do they serve?
> What benefits do they bring?
>
> > btw;
> > heres the definition of implement from dictionary.com
> >
> > im·ple·ment
> > 
> >  /n. '?mpl?m?nt; v. '?mpl??m?nt, -m?nt/ Pronunciation Key - Show Spelled
> > Pronunciation[n. *im*-pl*uh*-m*uh*nt; v. *im*-pl*uh*-ment, -m*uh*nt]
> > Pronunciation
> > Key - Show IPA Pronunciation -noun 1.any article used in some activity,
> > esp.
> > an instrument, tool, or utensil: agricultural implements.
> > notice the use of article; ie data; ie; you are wrong about member
> > variables
> > not being part of a classes implementation.
> > if a variable local to a function can be considered part of its
> > implementation; then a variable local to a class can be
> > considered part of its implementation; its that simple.
>
> Implementation is still an activity or a procedure. A lawnmower is a tool
> which implements lawnmowing, and it acts upon a lawn. However, the lawn is
> not part of the implementation, it is the subject of the implementation. An
> object may contain both variables and operations, but the data is not part
> of those operations, it is the subject of those operations.
>
> --
> Tony Marston
> http://www.tonymarston.net
> http://www.radicore.org
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

In response to:

> My point is that interfaces do not make anysense to me at all. I can access
> all my class methods without them, so what benefit do they give?

We first sought to use interfaces in our new app when we were at the
Best-Design-Ever stage but scaled them back more and more at each step
of the development. We have pretty much completed the first version of
the app (which contains maybe 90%

RE: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Jay Blanchard
[snip]
what is it suppose to return if it cannot find records that the exact
total do not match the total 
you are looking for?  should it return nothing?
[/snip]

Correct. It should say that there are no records that generate a match. 

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



Re: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Jim Lucas

Jay Blanchard wrote:

Good afternoon gurus and guru-ettes!

I am searching for an algorithm that will take a list of monetary values
and determine which of these values totals a value supplied to the
widget.

1. I supply a value to the application and give a date range
2. The application will query for all of the values in the date range
3. The application will determine which of the values will total the
supplied value
a. if the total values in the date range do not add up to the
supplied value the application will return that info. (I have this done
already)
4. The application will return the records comprising the total value
given


what is it suppose to return if it cannot find records that the exact total do not match the total 
you are looking for?  should it return nothing?



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Tony Marston

""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>>
>> There's your problem, then. You are wasting your time trying to implement
>> fancy design patterns just because design patterns are supposed to be
>> "cool".  Loader class, Controller Base class, Front Controller - I have
>> none
>> of that crap in my code, so I don't encounter the problems you have.
>>
>
> your site talks about the use of mvc in radicore so we can assume youre
> using at least one design pattern;

When I say that I do not use design patterns I mean that I do not try to 
implemet as many design patterns as possible, and I certainly do not litter 
my conversations with this pattern or that pattern. In the whole of my 
career there have only ever been two patterns that I have read about and 
subsequently sought to implement, and thoose are the Three Tier Architecture 
and the Singleton. The fact that my framework contains an example of MVC is 
pure coincidence. It just happened that way. It was only after someone else 
looked at my code and said "You've implemented the MVC pattern" that I read 
about it and discovered that it was a perfect match. I certainly did not 
read about MVC and then try to implement it.

> and if radicore has a single point of entry you
> are using a front controller.

I do not have a single point entry. Each page has its own controller, so I 
have hundreds of page controllers. A single front controller is something 
that is used in compiled languages.

> might want to knock the dust off the old design pattern books just to jog
> your memory:)

I've put my books of design patterns on the top shelf where they shall 
remain untouched as they contain nothing of use to me. They may give hints 
to novices, but I am no longer a novice. I no longer need training wheels on 
my bicycle, so why do I need books on design patterns?

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org 

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Tony Marston

""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>>
>>
>> ""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>> > On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
>> >>
>> >> Why would I use an interface? :)
>> >
>> > because inheritance is not always optimal.
>>
>> I have never found a prolem when using an interface was the only 
>> solution,
>> or even ANY kind of solution. The fact that your designs need it speaks
>> volumes of the problems with your designs.
>
> im not the one whose been defending my designs  in this conversation; you
> are.

But you are the one who keeps saying that your approach, where all member 
variables are hidden, is far superior. I'm just saying that I do share that 
opinion.

> there are plenty of situations where the interface is the more elegant
> approach, thats why its here; and thats why it was added in php5.
>
>> There's your problem, then. You are wasting your time trying to implement
>> fancy design patterns just because design patterns are supposed to be
>> "cool".
>
> i dont recall reading any suggestions to use design patterns because they
> are cool.

But you are the one who pointed out that interfaces are used in design 
patterns, therefore they *must* be OK. I am saying that I have never seen 
any advantages from using interfaces, and I don't waste my time with design 
patterns.

> infact the advice ive read is to only use them when they make sense.

My point is that interfaces do not make anysense to me at all. I can access 
all my class methods without them, so what benefit do they give?

> Loader class, Controller Base class, Front Controller - I have none
>> of that crap in my code, so I don't encounter the problems you have. When
>> I
>> see code like "$this->load->library('email') " I just thank my lucky 
>> stars
>> that I don't have to maintain it. I think some serious refactoring is 
>> long
>> overdue.
>
> id have to say code igniter is quite a bit more popular than radicore.
> maybe youre the one who has some refactoring to do.
>
> Perhaps you are trying to implement something from another language and
>> expecting PHP to be just like that other language, which is always a
>> stupid
>> mistake. PHP is different, therefore the solution will be different. I
>> suggest you learn how PHP works and design accordingly, and stop trying 
>> to
>> force it into emulating another language.
>
>
> well php has certainly gotten its influence from a number of other
> languages.
> where do you think the additional features in php5 got their inspiration
> from?

Some of those features were implemented just because some a*sholes who are 
more familiar with other languages keep saying "I can do so-and-so in 
language X, and I want to do exactly the same thing in PHP". Language X has 
interfaces, so PHP *must* have interfaces, Why? What purpose do they serve? 
What benefits do they bring?

> btw;
> heres the definition of implement from dictionary.com
>
> im·ple·ment
> 
>  /n. '?mpl?m?nt; v. '?mpl??m?nt, -m?nt/ Pronunciation Key - Show Spelled
> Pronunciation[n. *im*-pl*uh*-m*uh*nt; v. *im*-pl*uh*-ment, -m*uh*nt]
> Pronunciation
> Key - Show IPA Pronunciation -noun 1.any article used in some activity, 
> esp.
> an instrument, tool, or utensil: agricultural implements.
> notice the use of article; ie data; ie; you are wrong about member 
> variables
> not being part of a classes implementation.
> if a variable local to a function can be considered part of its
> implementation; then a variable local to a class can be
> considered part of its implementation; its that simple.

Implementation is still an activity or a procedure. A lawnmower is a tool 
which implements lawnmowing, and it acts upon a lawn. However, the lawn is 
not part of the implementation, it is the subject of the implementation. An 
object may contain both variables and operations, but the data is not part 
of those operations, it is the subject of those operations.

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org 

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



[PHP] Re: Something you can do with AJAX + PHP as well

2007-10-09 Thread tedd

At 5:52 PM +0100 10/9/07, Colin Guthrie wrote:

tedd wrote:

 Col:

 What do you think of this?

 http://webbytedd.com/b/timed-php/

 It's a combination of using both ajax and php together.


I'd say overkill for the end result (could be done in plain Javascript
without any "Ajax" calls), but then that's not really the point of the
page... it's more to demonstrate the methods rather than the end
results... and just goes to show that there are multiple methods of
removing the epidermus from a feline. :p

Col



Well yes, it is an overkill to simply display a gif in different 
positions over time -- but as you said, that was not the point of the 
demo.


While I may be just discovering what's obvious to everyone else, this 
has been an awakening for me. The idea that I could have processes 
going on in the background (server-side) and also communicate in real 
time with the user (client-side) as to what was happening was 
significant for me. Thus, my preparation of the demo. I see all sorts 
of applications.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>
> There's your problem, then. You are wasting your time trying to implement
> fancy design patterns just because design patterns are supposed to be
> "cool".  Loader class, Controller Base class, Front Controller - I have
> none
> of that crap in my code, so I don't encounter the problems you have.
>

your site talks about the use of mvc in radicore so we can assume youre
using
at least one design pattern; and if radicore has a single point of entry you
are
using a front controller.

might want to knock the dust off the old design pattern books just to jog
your memory:)

-nathan


RE: [PHP] Extracting text from PDF files

2007-10-09 Thread Jay Blanchard
[snip]
I need to extract the text from a PDF file for 
storage in the database.
[/snip]

It depends. If the PDF is an image file you cannot do it with PHP. 

http://www.php.net/pdf read the second user note


[snip]
Madison, WI 53703
[/snip]
P.S. Do you know of the Madison Scouts?

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



RE: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Jay Blanchard
[snip]
So imagine the value of all of your items is equal to it's size. Voila,
same problem.
[/snip]

Got it. I was focused to much on the forest and not the trees.

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



RE: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Instruct ICC

> CC: php-general@lists.php.net
> From: [EMAIL PROTECTED]
> Date: Tue, 9 Oct 2007 15:58:22 -0400
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] Looking for help with a complex algorithm
>
> And that is when I realize how much more I still need to learn about
> php...

IMHO, I don't think this has anything to do with PHP except he apparently wants 
to implement the algorithm in PHP.

Apparently any Turing complete language could do it.  (That's just a cool 
phrase I learned today on the information super highway).

_
Climb to the top of the charts!  Play Star Shuffle:  the word scramble 
challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_oct
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Instruct ICC

I never heard of the knapsack problem before this post.
But the w in the w*x terms appear to be 1, and he seems to want an exact value, 
not "less than or equal to".
I think my brute force factorial technique is a solution, but dynamic 
programming may be more efficient?  Not familiar with DP although I have heard 
of it.

Was someone suggesting a random walk?

_
Windows Live Hotmail and Microsoft Office Outlook – together at last.  Get it 
now.
http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL100626971033

[PHP] Extracting text from PDF files

2007-10-09 Thread Skip Evans

Hey all,

I need to extract the text from a PDF file for 
storage in the database.


Is there a way to do this in PHP?
--
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison, WI 53703
608-250-2720
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and versatile
PHP/MySQL, AJAX & DHTML development framework.
http://phpenguin.bigskypenguin.com/

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



RE: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Robert Cummings
On Tue, 2007-10-09 at 15:28 -0500, Jay Blanchard wrote:
> [snip]
> This *IS* the knapsack problem. Just because you specify date ranges to
> get your values and the value isn't a knapsack doesn't change the fact
> that it is the same problem :) I remember having fun with genetic
> algorithms and the knapsack problem back in University.
> [/snip]
> 
> You're right save for the knapsack problem considered not only volume,
> but value as well.

So imagine the value of all of your items is equal to it's size. Voila,
same problem.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Daniel Brown
On 10/9/07, Jay Blanchard <[EMAIL PROTECTED]> wrote:
> [snip]
> This *IS* the knapsack problem. Just because you specify date ranges to
> get your values and the value isn't a knapsack doesn't change the fact
> that it is the same problem :) I remember having fun with genetic
> algorithms and the knapsack problem back in University.
> [/snip]
>
> You're right save for the knapsack problem considered not only volume,
> but value as well.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Keep in mind that I only wrote this in a few minutes just now, and
only for fun, so it's sloppy and not very well planned.  In any case,
I hope it might be able to help you solve your problem, Jay
(tested from the CLI because I'm in the middle of doing something else
right now)

 $v) {
echo "Busted at ".$try."!\n";
$i = $attempts;
}
} else {
$i--;
}
}
if($done === True) {
break;
}
}

for($i=0;$i


-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

Give a man a fish, he'll eat for a day.  Then you'll find out he was
allergic and is hospitalized.  See?  No good deed goes unpunished

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



RE: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Jay Blanchard
[snip]
This *IS* the knapsack problem. Just because you specify date ranges to
get your values and the value isn't a knapsack doesn't change the fact
that it is the same problem :) I remember having fun with genetic
algorithms and the knapsack problem back in University.
[/snip]

You're right save for the knapsack problem considered not only volume,
but value as well.

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Robert Cummings
On Tue, 2007-10-09 at 16:18 -0400, Robert Cummings wrote:
> On Tue, 2007-10-09 at 14:11 -0400, Andrew Ballard wrote:
> > On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> > > Certainly you'll notice I've extended the original class,
> > > overriden the __wakeup() call and basically used inheritance
> > > and polymorphism to my advantage.
> > 
> > Noticed. :-) I said a *little* more difficult. Of course, I could
> > declare the class final, but then that ends any chance at inheritance.
> > 
> > > I would argue that this kind of tampering isn't worth checking for on
> > > every unserialize.
> > 
> > I haven't done much with PHP objects (other than built-in objects),
> > and can't recall a case where I've used serialize/unserialize for
> > anything other than to inspect variables before functions like
> > var_dump during development. In that case, your example concerns me
> > more with what other developers might try to do to circumvent
> > protections built into an object. It's a good argument for not storing
> > objects in anything persistent, like session variables, though, since
> > those are serialized/unserialized on every page and often stored in
> > the physical file system.
> > 
> > Honestly, it all seems a bit extreme. At some point, you have to trust
> > the people you work with not to go to such lengths to violate an
> > objects contract -- which I guess goes back to Tony's point whether
> > the language "enforces" private members/functions or whether they are
> > simply regarded that way by the developers using them. I would prefer
> > both, honestly. :)
> 
> If you're really worried about tampering of serialized data, store the
> SHA1 code for the serialized data and validate before unserializing.

In retrospect that doesn't really help if someone has access to both :)

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Robert Cummings
On Tue, 2007-10-09 at 14:11 -0400, Andrew Ballard wrote:
> On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> > Certainly you'll notice I've extended the original class,
> > overriden the __wakeup() call and basically used inheritance
> > and polymorphism to my advantage.
> 
> Noticed. :-) I said a *little* more difficult. Of course, I could
> declare the class final, but then that ends any chance at inheritance.
> 
> > I would argue that this kind of tampering isn't worth checking for on
> > every unserialize.
> 
> I haven't done much with PHP objects (other than built-in objects),
> and can't recall a case where I've used serialize/unserialize for
> anything other than to inspect variables before functions like
> var_dump during development. In that case, your example concerns me
> more with what other developers might try to do to circumvent
> protections built into an object. It's a good argument for not storing
> objects in anything persistent, like session variables, though, since
> those are serialized/unserialized on every page and often stored in
> the physical file system.
> 
> Honestly, it all seems a bit extreme. At some point, you have to trust
> the people you work with not to go to such lengths to violate an
> objects contract -- which I guess goes back to Tony's point whether
> the language "enforces" private members/functions or whether they are
> simply regarded that way by the developers using them. I would prefer
> both, honestly. :)

If you're really worried about tampering of serialized data, store the
SHA1 code for the serialized data and validate before unserializing.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Robert Cummings
On Tue, 2007-10-09 at 14:01 -0500, Jay Blanchard wrote:
> Good afternoon gurus and guru-ettes!
> 
> I am searching for an algorithm that will take a list of monetary values
> and determine which of these values totals a value supplied to the
> widget.
> 
> 1. I supply a value to the application and give a date range
> 2. The application will query for all of the values in the date range
> 3. The application will determine which of the values will total the
> supplied value
>   a. if the total values in the date range do not add up to the
> supplied value the application will return that info. (I have this done
> already)
> 4. The application will return the records comprising the total value
> given
> 
> For instance I supply 10.22 and a date range of 2007-10-01 to 2007-10-05
> 
> Values in the range;
> 3.98
> 9.77
> 3.76
> 4.13
> 7.86
> 1.45
> 12.87
> 10.01
> 0.88
> 
> Values comprising the total;
> 3.76
> 4.13
> 1.45
> 0.88
> 
> It is possible to have duplicate values, so we will have to assume that
> the first one of the dupes is correct, the records will be sorted by
> date. I have been working with a recursive function, but so far the
> results are not pretty and it is getting too complex.
> 
> FYI, this is very similar to the "knapsack problem"" in dynamic
> programming.

This *IS* the knapsack problem. Just because you specify date ranges to
get your values and the value isn't a knapsack doesn't change the fact
that it is the same problem :) I remember having fun with genetic
algorithms and the knapsack problem back in University.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Jason Pruim
And that is when I realize how much more I still need to learn about  
php...


On Oct 9, 2007, at 3:01 PM, Jay Blanchard wrote:


Good afternoon gurus and guru-ettes!

I am searching for an algorithm that will take a list of monetary  
values

and determine which of these values totals a value supplied to the
widget.

1. I supply a value to the application and give a date range
2. The application will query for all of the values in the date range
3. The application will determine which of the values will total the
supplied value
a. if the total values in the date range do not add up to the
supplied value the application will return that info. (I have this  
done

already)
4. The application will return the records comprising the total value
given

For instance I supply 10.22 and a date range of 2007-10-01 to  
2007-10-05


Values in the range;
3.98
9.77
3.76
4.13
7.86
1.45
12.87
10.01
0.88

Values comprising the total;
3.76
4.13
1.45
0.88

It is possible to have duplicate values, so we will have to assume  
that

the first one of the dupes is correct, the records will be sorted by
date. I have been working with a recursive function, but so far the
results are not pretty and it is getting too complex.

FYI, this is very similar to the "knapsack problem"" in dynamic
programming.

Just another challenging day in paradise!

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




--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]

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



RE: [PHP] Looking for help with a complex algorithm

2007-10-09 Thread Instruct ICC


> Date: Tue, 9 Oct 2007 14:01:30 -0500
> From: [EMAIL PROTECTED]
> To: php-general@lists.php.net
> Subject: [PHP] Looking for help with a complex algorithm
>
> Good afternoon gurus and guru-ettes!
>
> I am searching for an algorithm that will take a list of monetary values
> and determine which of these values totals a value supplied to the
> widget.
>
> 1. I supply a value to the application and give a date range
> 2. The application will query for all of the values in the date range
> 3. The application will determine which of the values will total the
> supplied value
> a. if the total values in the date range do not add up to the
> supplied value the application will return that info. (I have this done
> already)
> 4. The application will return the records comprising the total value
> given
>
> For instance I supply 10.22 and a date range of 2007-10-01 to 2007-10-05
>
> Values in the range;
> 3.98
> 9.77
> 3.76
> 4.13
> 7.86
> 1.45
> 12.87
> 10.01
> 0.88
>
> Values comprising the total;
> 3.76
> 4.13
> 1.45
> 0.88
>
> It is possible to have duplicate values, so we will have to assume that
> the first one of the dupes is correct, the records will be sorted by
> date. I have been working with a recursive function, but so far the
> results are not pretty and it is getting too complex.
>
> FYI, this is very similar to the "knapsack problem"" in dynamic
> programming.
>
> Just another challenging day in paradise!

The first thing that came to my mind was factorials.  So that may be why it got 
complicated quickly.  You still need your recursion, but by following a 
factorial pattern.
Given:
1 2 3

Test:
1
1+2
1+2+3

1+3

2
2+3

3

Given:
1 2 3 4

Test:
1
1+2
1+2+3
1+2+3+4

1+3
1+3+4

1+4

2
2+3
2+3+4
2+4

3
3+4

4

And I'm not sure if that covers all for the case of 3 or 4 values.
Something like Permutation as opposed to Combination
http://www.gomath.com/algebra/probability.php
_
Help yourself to FREE treats served up daily at the Messenger Café. Stop by 
today.
http://www.cafemessenger.com/info/info_sweetstuff2.html?ocid=TXT_TAGLM_OctWLtagline
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to format CLI tabular data?

2007-10-09 Thread Jim Lucas

tedd wrote:

At 12:05 AM -0700 10/9/07, Jim Lucas wrote:

Daevid Vincent wrote:

Does PHP have any tools like this? I'd prefer not to pull in some PEAR
package or other bloat, but I'll take what I can get if it actually 
works
well. I was hoping there are some tips/tricks to show simple tabular 
data:

-snip-
notice basic things like alignment, length of data (as in 'tabs' 
won't work), etc.




Try this out


-snip- code

Jim:

Thanks for the code. I've altered it to display a table in a browser:

http://webbytedd.com/bbb/table/

Code is shown there.

Cheers,

tedd


Wasn't he asking for something that was to display in the console?

I wouldn't use that to display tabular data in a browser.

I will attach what I use to display in a browser.

I updated the comments, I think everything is correct.  Let me know what you 
think

addHeader(   array('ID', 'FirstName','LastName'),
'header');
 *  $table->addData( array(1,'Jim',  'L'),   
'rowA');
 *  $table->addData( array(2,'Tim',  'H'),   
'rowB');
 *  $table->addData( array(1,'Jim',  'B'),   
'rowA');
 *  $table->addData( array(2,'Chris','C'),   
'rowB');
 *  echo $table->get('table_one', 'some_class');
 *
 *  or
 *
 *  $data[] = array('id' => 1,   'first_name' => 'John',  
'last_name' => 'Doe');
 *  $data[] = array('id' => 2,   'first_name' => 'Jonny', 'last_name' 
=> 'Buck');
 *  $data[] = array('id' => 3,   'first_name' => 'James', 'last_name' 
=> 'Smith');
 *  $table = new table();
 *  $table->dump($dataArray);
 *  echo $table->to_s();
 */
class table {
/**
 * Purpose is to contain table data for display purposes later
 *
 * @typearray()
 */
var $table  = array();
/**
 * Constructor.
 *
 * @return  Class Object
 */
function __construct() {
return $this;
}
/**
 * Constructor, php4 style
 *
 * @return  Class Object
 */
function table() {
return $this->__construct();
}
/**
 * Creates a table header row
 *
 * This calls to the addRow method to create a list of cells with the 
$data submitted
 * It creates ... cells
 *
 * @param   Your 1-dimensional array of data
 * @param   Value you would like to set id for the  tag
 *
 * @return  Class Object
 */
function addHeader($data, $row_id=null) {
$this->addRow($data, 'th', $row_id);
return $this;
}
/**
 * Creates a table data row
 *
 * This calls to the addRow method to create a list of cells with the 
$data submitted
 * It creates ... cells
 *
 * @param   Your 1-dimensional array of data
 * @param   Value you would like to set id for the  tag
 *
 * @return  Class Object
 */
function addData($data, $row_id=null) {
$this->addRow($data, 'td', $row_id);
return $this;
}
/**
 * Creates a table row, when called
 *
 * @param   Data to be displayed
 * @param   Which type of cells are we creating?  td (default) or th
 * @param   ID value to be appended to the  tag
 *
 * @return  Class Object
 */
function addRow($data, $type='td', $row_id=null) {
$this->table[] = "";
foreach ( $data AS $id => $cell ) {
$this->table[] = "<{$type} class='col_{$id}'>".
htmlspecialchars($cell)."";
}
$this->table[] = '';
return $this;
}
/**
 * Just build a table from an array full of data
 *
 * @param   Your 2-dimensional array of data
 *
 * @return  Class Object
 */
function dump($data=array()) {
for ( $x=0; $xaddHeader(array_keys($data[$x]));
}
$this->addData($data[$x]);
}
return $this;
}
/**
 * Generate and return the built table
 *
 * @param   Specify the ID value for the table id attribute
 * @param   Specify a class for the table class attribute
 *
 * @return  if data found, return formatted table
 *  if no data found, return 'No data to display' message
 */
function get($id='', $class='') {
if ( count($this->table) ) {
return "\n\n".
join("\n", $this->table)."\n\n";

[PHP] Looking for help with a complex algorithm

2007-10-09 Thread Jay Blanchard
Good afternoon gurus and guru-ettes!

I am searching for an algorithm that will take a list of monetary values
and determine which of these values totals a value supplied to the
widget.

1. I supply a value to the application and give a date range
2. The application will query for all of the values in the date range
3. The application will determine which of the values will total the
supplied value
a. if the total values in the date range do not add up to the
supplied value the application will return that info. (I have this done
already)
4. The application will return the records comprising the total value
given

For instance I supply 10.22 and a date range of 2007-10-01 to 2007-10-05

Values in the range;
3.98
9.77
3.76
4.13
7.86
1.45
12.87
10.01
0.88

Values comprising the total;
3.76
4.13
1.45
0.88

It is possible to have duplicate values, so we will have to assume that
the first one of the dupes is correct, the records will be sorted by
date. I have been working with a recursive function, but so far the
results are not pretty and it is getting too complex.

FYI, this is very similar to the "knapsack problem"" in dynamic
programming.

Just another challenging day in paradise!

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Andrew Ballard <[EMAIL PROTECTED]> wrote:
>
> Honestly, it all seems a bit extreme. At some point, you have to trust
> the people you work with not to go to such lengths to violate an
> objects contract -- which I guess goes back to Tony's point whether
> the language "enforces" private members/functions or whether they are
> simply regarded that way by the developers using them. I would prefer
> both, honestly. :)
>


indeed.

-nathan


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Andrew Ballard
On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> Certainly you'll notice I've extended the original class,
> overriden the __wakeup() call and basically used inheritance
> and polymorphism to my advantage.

Noticed. :-) I said a *little* more difficult. Of course, I could
declare the class final, but then that ends any chance at inheritance.

> I would argue that this kind of tampering isn't worth checking for on
> every unserialize.

I haven't done much with PHP objects (other than built-in objects),
and can't recall a case where I've used serialize/unserialize for
anything other than to inspect variables before functions like
var_dump during development. In that case, your example concerns me
more with what other developers might try to do to circumvent
protections built into an object. It's a good argument for not storing
objects in anything persistent, like session variables, though, since
those are serialized/unserialized on every page and often stored in
the physical file system.

Honestly, it all seems a bit extreme. At some point, you have to trust
the people you work with not to go to such lengths to violate an
objects contract -- which I guess goes back to Tony's point whether
the language "enforces" private members/functions or whether they are
simply regarded that way by the developers using them. I would prefer
both, honestly. :)


Andrew

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>
>
> ""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> >>
> >> Why would I use an interface? :)
> >
> > because inheritance is not always optimal.
>
> I have never found a prolem when using an interface was the only solution,
> or even ANY kind of solution. The fact that your designs need it speaks
> volumes of the problems with your designs.


im not the one whose been defending my designs  in this conversation; you
are.
there are plenty of situations where the interface is the more elegant
approach,
thats why its here; and thats why it was added in php5.

>
> There's your problem, then. You are wasting your time trying to implement
> fancy design patterns just because design patterns are supposed to be
> "cool".


i dont recall reading any suggestions to use design patterns because they
are cool.
infact the advice ive read is to only use them when they make sense.

Loader class, Controller Base class, Front Controller - I have none
> of that crap in my code, so I don't encounter the problems you have. When
> I
> see code like "$this->load->library('email') " I just thank my lucky stars
> that I don't have to maintain it. I think some serious refactoring is long
> overdue.


id have to say code igniter is quite a bit more popular than radicore.
maybe youre the one who has some refactoring to do.

Perhaps you are trying to implement something from another language and
> expecting PHP to be just like that other language, which is always a
> stupid
> mistake. PHP is different, therefore the solution will be different. I
> suggest you learn how PHP works and design accordingly, and stop trying to
> force it into emulating another language.


well php has certainly gotten its influence from a number of other
languages.
where do you think the additional features in php5 got their inspiration
from?

btw;
heres the definition of implement from dictionary.com

im·ple·ment

  /n. ˈɪmpləmənt; v. ˈɪmpləˌmɛnt, -mənt/ Pronunciation Key - Show Spelled
Pronunciation[n. *im*-pl*uh*-m*uh*nt; v. *im*-pl*uh*-ment, -m*uh*nt]
Pronunciation
Key - Show IPA Pronunciation –noun 1.any article used in some activity, esp.
an instrument, tool, or utensil: agricultural implements.
notice the use of article; ie data; ie; you are wrong about member variables
not being part of a classes implementation.
if a variable local to a function can be considered part of its
implementation; then a variable local to a class can be
considered part of its implementation; its that simple.


-nathan


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Tony Marston

""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
>>
>> Why would I use an interface? :)
>
> because inheritance is not always optimal.

I have never found a prolem when using an interface was the only solution, 
or even ANY kind of solution. The fact that your designs need it speaks 
volumes of the problems with your designs.

> What's the problem that's outlined? I'm too lazy to go and look :|
>
> /**
> * CI_BASE - For PHP 4
> *
> * This file is used only when CodeIgniter is being run under PHP 4.
> *
> * In order to allow CI to work under PHP 4 we had to make the Loader class
> * the parent of the Controller Base class.  It's the only way we can
> * enable functions like $this->load->library('email') to instantiate
> * classes that can then be used within controllers as $this->email->send()
> *
> * PHP 4 also has trouble referencing the CI super object within 
> application
> * constructors since objects do not exist until the class is fully
> * instantiated.  Basically PHP 4 sucks...
> *
> * Since PHP 5 doesn't suffer from this problem so we load one of
> * two files based on the version of PHP being run.
> *
> * @packageCodeIgniter
> * @subpackagecodeigniter
> * @categoryfront-controller
> * @authorRick Ellis
> * @linkhttp://www.codeigniter.com/user_guide/
> */
>
> -nathan
>

There's your problem, then. You are wasting your time trying to implement 
fancy design patterns just because design patterns are supposed to be 
"cool".  Loader class, Controller Base class, Front Controller - I have none 
of that crap in my code, so I don't encounter the problems you have. When I 
see code like "$this->load->library('email') " I just thank my lucky stars 
that I don't have to maintain it. I think some serious refactoring is long 
overdue.

Perhaps you are trying to implement something from another language and 
expecting PHP to be just like that other language, which is always a stupid 
mistake. PHP is different, therefore the solution will be different. I 
suggest you learn how PHP works and design accordingly, and stop trying to 
force it into emulating another language.

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org 

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Robert Cummings
On Tue, 2007-10-09 at 13:15 -0400, Nathan Nobbe wrote:
> On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> >
> > Why would I use an interface? :)
> 
> 
> because inheritance is not always optimal.
> 
> What's the problem that's outlined? I'm too lazy to go and look :|
> 
> 
> /**
>  * CI_BASE - For PHP 4
>  *
>  * This file is used only when CodeIgniter is being run under PHP 4.
>  *
>  * In order to allow CI to work under PHP 4 we had to make the Loader class
>  * the parent of the Controller Base class.  It's the only way we can
>  * enable functions like $this->load->library('email') to instantiate
>  * classes that can then be used within controllers as $this->email->send()
>  *
>  * PHP 4 also has trouble referencing the CI super object within application
>  * constructors since objects do not exist until the class is fully
>  * instantiated.  Basically PHP 4 sucks...
>  *
>  * Since PHP 5 doesn't suffer from this problem so we load one of
>  * two files based on the version of PHP being run.
>  *
>  * @packageCodeIgniter
>  * @subpackagecodeigniter
>  * @categoryfront-controller
>  * @authorRick Ellis
>  * @linkhttp://www.codeigniter.com/user_guide/
>  */

Having read the comment it sounds like they have a solution in place.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Robert Cummings
On Tue, 2007-10-09 at 12:40 -0400, Andrew Ballard wrote:
> On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> > $sucker = new TryToViolateEncapsulation();
> > $sucker = (array)$sucker;
> >
> > $keys = array_keys( $sucker );
> > $sucker[reset( $keys )] = 500;
> >
> > $sucker = serialize( (object)$sucker );
> > $sucker = 'O:25:"TryToViolateEncapsulation"'.substr( $sucker, 14 );
> > $sucker = unserialize( $sucker );
> >
> > print_r( $sucker );
> >
> > :::
> >
> > Maybe next time you'll have a challenge for me ;) And don't whine about
> > how I achieved what I did.
> >
> >
> That's a bit disturbing. Ok, while we're bending things a bit, I'll
> make it a *little* tougher. :-)
> 
> class TryToViolateEncapsulation {
> private $someInt = 0;
> 
> const MAX_INT = 100;
> const MIN_INT = 0;
> 
> public function getSomeInt() {
>return $this->someInt;
> }
> 
> public function setSomeInt($someInt) {
> $success = false;  // assume failure
> $someInt = (int) $someInt;
> if($this->isValid($someInt)) {
>   $this->someInt = $someInt;
>   $success = true;
> } else {
>   throw new InvalidArgumentException('Invalid value passed to
> setSomeInt');
> }
> 
> return $success;
> }
> 
> private function isValid($someInt) {
>$isValid = true;
>if($someInt < TryToViolateEncapsulation::MIN_INT  || $someInt >
> TryToViolateEncapsulation::MAX_INT) {
>   $isValid = false;
>}
>return $isValid;
>}
> 
>public function __wakeup() {
>   $this->setSomeInt($this->someInt);
>}
> }

class Tricky extends TryToViolateEncapsulation
{
function __wakeup()
{
}

function bleh( TryToViolateEncapsulation $obj )
{
echo 'Gotta love it!!'."\n"; 
}
}
 
function objectCast( &$object, $class )
{
$newObject =
'O:'.strlen( $class ).':"'.$class.'"'
   .substr( serialize( (object)(array)$object ), 14 );

$newObject = unserialize( $newObject );

$object = $newObject;
}
 
function arraySetPrivateField( &$objectArray, $className, $fieldName, $value )
{
$objectArray["\x00$className\x00$fieldName"] = $value;
}
 
 
$sucker = new TryToViolateEncapsulation();
$sucker = (array)$sucker;

arraySetPrivateField( $sucker, 'TryToViolateEncapsulation', 'someInt', 300 );
objectCast( $sucker, 'Tricky' );


print_r( $sucker );
$sucker->bleh( $sucker );



Certainly you'll notice I've extended the original class,
overriden the __wakeup() call and basically used inheritance
and polymorphism to my advantage. The object is now of a
different class but will serve in all contexts that one
expects the parent class unless an explicit class type check
is made. I think it's sufficient though since I've still
modified the private member variable of the parent ;)

> Of course, my gripe with __wakeup is that it is essentially a PHP
> implementation function that, IMO, should be private. However, it must
> be declared public for it to work, and that means that anyone outside
> the class can call it whenever they want.
> 
> While I'm not totally sold on OOP for web pages, I still like PHP5
> because of the OO enhancements over PHP4. Can you code without them?
> Sure. I can cut my grass with a push mower, too -- but I tend to like
> my lawn tractor much better.
> 
> However, thank you for demonstrating that I need to be MUCH more
> careful when building objects to validate member values each time they
> are used, and not just when they are set.

I would argue that this kind of tampering isn't worth checking for on
every unserialize.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



[PHP] Download and Upload of Files

2007-10-09 Thread Rodolfo De Nadai

Hi there guys

i developed an app that uses AJAX, ActiveX objects and PHP to download 
and upload files from local machine to the server... everything works 
great, i can transfer office files and even exe files. The problem i'm 
face is to transfer mp3 files and pdf files... anybody already try do 
something like these?? If not, how can i get a file with php without the 
use of a html form or even the enctype = multipart/form-data??
To get the files i'm using $GLOBALS["HTTP_RAW_POST_DATA"], because the 
file_get_contents give the memory size error even if i send half of the 
memory size allowed...


And another question, binary data in mp3 or pdf files have some 
character that can give some type of error when send over the internet???


thanks for any help!
--
* Rodolfo De Nadai *
* Analista de Sistema Jr. - Desenvolvimento *




*Informática de Municípios Associados S.A.*
Seu governo mais inteligente
[EMAIL PROTECTED]   - 
www.ima.sp.gov.br 
Fone: (19) 3739-6000 / Ramal: 1307 


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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
> Why would I use an interface? :)


because inheritance is not always optimal.

What's the problem that's outlined? I'm too lazy to go and look :|


/**
 * CI_BASE - For PHP 4
 *
 * This file is used only when CodeIgniter is being run under PHP 4.
 *
 * In order to allow CI to work under PHP 4 we had to make the Loader class
 * the parent of the Controller Base class.  It's the only way we can
 * enable functions like $this->load->library('email') to instantiate
 * classes that can then be used within controllers as $this->email->send()
 *
 * PHP 4 also has trouble referencing the CI super object within application
 * constructors since objects do not exist until the class is fully
 * instantiated.  Basically PHP 4 sucks...
 *
 * Since PHP 5 doesn't suffer from this problem so we load one of
 * two files based on the version of PHP being run.
 *
 * @packageCodeIgniter
 * @subpackagecodeigniter
 * @categoryfront-controller
 * @authorRick Ellis
 * @linkhttp://www.codeigniter.com/user_guide/
 */

-nathan


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Robert Cummings
On Tue, 2007-10-09 at 11:49 -0400, Nathan Nobbe wrote:
> On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> >
> > Maybe next time you'll have a challenge for me ;)
> 
> 
> bravo!  i expected you would come up w/ something.
> 
> And don't whine about
> > how I achieved what I did.
> >
> 
> fair enough.
> 
> 
> maybe for your next trick youll build an interface in php4;

Why would I use an interface? :)

> or address the problem outlined in the code igniter comment.

What's the problem that's outlined? I'm too lazy to go and look :|

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



[PHP] Re: Something you can do with AJAX + PHP as well

2007-10-09 Thread Colin Guthrie
tedd wrote:
> Col:
> 
> What do you think of this?
> 
> http://webbytedd.com/b/timed-php/
> 
> It's a combination of using both ajax and php together.

I'd say overkill for the end result (could be done in plain Javascript
without any "Ajax" calls), but then that's not really the point of the
page... it's more to demonstrate the methods rather than the end
results... and just goes to show that there are multiple methods of
removing the epidermus from a feline. :p

Col

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



[PHP] Re: Something you can do with AJAX + PHP as well

2007-10-09 Thread tedd

Jay Blanchard wrote:

 [snip]
 I saved it and it played in Winamp, but no audio
 [/snip]

 So, is it worth going to all of the trouble to see?



In a word, "no".

I watched it fine in Firefox on Linux with mplayer pluing. It just
worked(tm) for me!

But overall I have to say I was somewhat disappointed. It was just your
standard Ajax stuff really, nothing PHP related at all and nothing that
isn't done slicker on Facebook and Flickr and other good Web 2.0 sites.

Sorry Mark but that's just the way it is. I'm sure it's useful in the
context but I wouldn't say it's rocket science or visually impressive.

Col


Col:

What do you think of this?

http://webbytedd.com/b/timed-php/

It's a combination of using both ajax and php together.

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Andrew Ballard
On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> $sucker = new TryToViolateEncapsulation();
> $sucker = (array)$sucker;
>
> $keys = array_keys( $sucker );
> $sucker[reset( $keys )] = 500;
>
> $sucker = serialize( (object)$sucker );
> $sucker = 'O:25:"TryToViolateEncapsulation"'.substr( $sucker, 14 );
> $sucker = unserialize( $sucker );
>
> print_r( $sucker );
>
> :::
>
> Maybe next time you'll have a challenge for me ;) And don't whine about
> how I achieved what I did.
>
>
That's a bit disturbing. Ok, while we're bending things a bit, I'll
make it a *little* tougher. :-)

class TryToViolateEncapsulation {
private $someInt = 0;

const MAX_INT = 100;
const MIN_INT = 0;

public function getSomeInt() {
   return $this->someInt;
}

public function setSomeInt($someInt) {
$success = false;  // assume failure
$someInt = (int) $someInt;
if($this->isValid($someInt)) {
  $this->someInt = $someInt;
  $success = true;
} else {
throw new InvalidArgumentException('Invalid value passed to
setSomeInt');
}

return $success;
}

private function isValid($someInt) {
   $isValid = true;
   if($someInt < TryToViolateEncapsulation::MIN_INT  || $someInt >
TryToViolateEncapsulation::MAX_INT) {
  $isValid = false;
   }
   return $isValid;
   }

   public function __wakeup() {
$this->setSomeInt($this->someInt);
   }
}

Of course, my gripe with __wakeup is that it is essentially a PHP
implementation function that, IMO, should be private. However, it must
be declared public for it to work, and that means that anyone outside
the class can call it whenever they want.

While I'm not totally sold on OOP for web pages, I still like PHP5
because of the OO enhancements over PHP4. Can you code without them?
Sure. I can cut my grass with a push mower, too -- but I tend to like
my lawn tractor much better.

However, thank you for demonstrating that I need to be MUCH more
careful when building objects to validate member values each time they
are used, and not just when they are set.

Andrew

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Tony Marston

""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>>
>> You are confusing member variables with local variables. Member variables
>> are part of the object's data which need to be made available to the
>> outside
>> world. Local variables are internal to the function, and do not need to 
>> be
>> made available to the outside world. Local variables are part of the
>> implementation, member varables are not.
>
>
> no im not confusing anything;
> local variables are within the scope of the function; therefore they are
> part of the function
> implementation.
> instance variables are part of the scope of a class instance, therefore 
> they
> are part of its
> implementation.
>
> "Implementation" means the act of changing data, therefore it means the 
> code
>> and not the data itself.
>
>
> code is nothing w/o data to manipulate; what is an algorithm w/o data to
> manipulate; it simply would not exist.

I disagree. The dictionary definition of "implementation" is "an activity or 
process". The fact that an implementation works with data does not make that 
data part of that implementation. Data is free standing and can be 
maniplated by several different implementations, and an implementation can 
work with with any set of data. So implementation, or the activity/process, 
means nothing more than the code, with the data being separate and 
independent.

> 
>>
>> > it is also about client code not being able to  view and manipulate the
>> > implementation.
>> > if client code can access data that the implementation (as you define 
>> > it
>> > [not consisting of data])
>> > uses, or relys upon, then the outcome of the implementation can be
>> > altered by client code.
>>
>> Then surely if a programmer fucks things up in such a fashion it would
>> become apparent during unit testing? Then the culprit can be soundly
>> whipped until he learns NOT to fuck up.
>
> or better yet; protect the  implementation so he wouldnt have to be 
> whipped
> in the first place.

A bad programmer will ALWAYS find new and obscure ways to fuck up. Isn't it 
the abuse of inheritance which spawned the idea of object composition as a 
replacement for inheritace?

>> that is a violation of encapsulation,
>>
>> I disagree.Encapsulation is the act of placing the data, and the
>> operations
>> which act upon that data, in the same object. A violation of 
>> encapsulation
>> is therefore to put the data and its operations in more than one object.
>> Encapsulation has absolutely nothing to do with how those objects are 
>> used
>> (or abused).
>>
>> > The fundamental concepts of OOP consist of nothing more than
>> > encapsulation, inheritance and polymorphism. Data hiding, interfaces
>> > and all that other fancy stuff are irrelevant.
>> >
>> > youre missing out on like the last decade or so of oop.
>>
>> I am sticking to the fundamentals and deliberately ignoring all the crap
>> which has been added on by everybody and his dog.
>
> hmm; the rest of the oop community seems to be flocking to the crap.

The fact that others flock like mindless sheep to the latest fad or fancy 
just shows how gullible they are.

>> >>> im not going to take the
>> >>> time to try and explain the power of the interface construct.  imho,
>> >>> you have a long way to
>> >>> go before you can grasp the power of the mechanism.
>> >>
>> >> I have never seen any gain from using interfaces in PHP, only pain,
>> >> therefore I refuse to use them. Yet what functinality I am losing? 
>> >> None
>> >> whatsoever.
>> >
>> > not every system will benefit from interfaces.
>> > it sounds like you dont fully understand the use of them; and i wont 
>> > say
>> > its immediately obvious.
>>
>> If it is not obvious in the way that interfaces can provide benefits then
>> they are useless as far as I am concerned. I have never seen ANY
>> documentation which shows ANY benefits from using interfaces, so I simply
>> do not see the point in using them.
>>
>> > as i said they offer an additional polymorphic mechanism
>> > one that php4 doesnt supply.
>>
>> I can achieve all the polymorphism I need WITHOUT using interfaces, so I
>> do not see the point in using them.
>
>
> like i said not every system will benefit.
>
>> >if you want a great example of how they are used and when extension is 
>> >not
>> > desirable (because the behavior is passed along) read the first chapter
>> > of heads first design patterns.
>>
>> I refuse to read any more books on design patterns. In my opinion they 
>> are
>> abused, over-used and over-rated. Just because one or two design patterns
>> use interfaces does not mean that interfaces are the best thing since
>> sliced
>> bread.
>
>
> it would be nice if you saw just one example why they are sometimes better
> than inheritance and therefore useful.

I have bought and read several books on design patterns without being 
impressed. I have seen countless examples of how parti

Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Robert Cummings
On Tue, 2007-10-09 at 11:41 -0400, Christoph Boget wrote:
> >
> > Maybe next time you'll have a challenge for me ;) And don't whine about
> > how I achieved what I did.
> 
> 
> Brilliant!  I never would have thought of that. ;)

It gets easier... here's a quick toolset for completely violating PHP5
objects :)

function objectCast( &$object, $class )
{
$newObject =
'O:'.strlen( $class ).':"'.$class.'"'
   .substr( serialize( (object)(array)$object ), 14 );

$newObject = unserialize( $newObject );

$object = $newObject;
}
 
function arraySetPrivateField
( &$objectArray, $className, $fieldName, $value )
{
$objectArray["\x00$className\x00$fieldName"] = $value;
}
 
 
echo "\n";

$sucker = new TryToViolateEncapsulation();
$sucker = (array)$sucker;

print_r( $sucker );

arraySetPrivateField( $sucker, 'TryToViolateEncapsulation', 'someInt',
501 );
objectCast( $sucker, 'TryToViolateEncapsulation' );

print_r( $sucker );


-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
> Maybe next time you'll have a challenge for me ;)


bravo!  i expected you would come up w/ something.

And don't whine about
> how I achieved what I did.
>

fair enough.


maybe for your next trick youll build an interface in php4; or address the
problem outlined in
the code igniter comment.

-nathan


Re: [PHP] Chmod a Directory

2007-10-09 Thread Daniel Brown
On 10/9/07, tedd <[EMAIL PROTECTED]> wrote:
> At 12:00 PM +0200 10/9/07, Samuel Vogel wrote:
> >You will have to loop through the directory recursively, running
> >chmod() on every file there is!
> >
> >Regards,
> >Samy
>
> Isn't there a sticky bit thing (i.e., 1777) you can use to change the
> files inside a directory?
>
> I've never done it, but I remember reading about it.
>
> Daniel Brown posted a magnificent post about permissions one time,
> but I can't find it. Perhaps he would be so kind as to post it again?
>
> Cheers,
>
> tedd
> --
> ---
> http://sperling.com  http://ancientstones.com  http://earthstones.com
>

Thanks, Tedd!

I had to search for it, and wasn't having much luck, but GMANE has
a copy of it, posted 18 May, 2007.

http://article.gmane.org/gmane.comp.php.general/163539


-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

Give a man a fish, he'll eat for a day.  Then you'll find out he was
allergic and is hospitalized.  See?  No good deed goes unpunished

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Christoph Boget
>
> Maybe next time you'll have a challenge for me ;) And don't whine about
> how I achieved what I did.


Brilliant!  I never would have thought of that. ;)

thnx,
Christoph


Re: [PHP] Chmod a Directory

2007-10-09 Thread tedd

At 12:00 PM +0200 10/9/07, Samuel Vogel wrote:
You will have to loop through the directory recursively, running 
chmod() on every file there is!


Regards,
Samy


Isn't there a sticky bit thing (i.e., 1777) you can use to change the 
files inside a directory?


I've never done it, but I remember reading about it.

Daniel Brown posted a magnificent post about permissions one time, 
but I can't find it. Perhaps he would be so kind as to post it again?


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Robert Cummings
On Tue, 2007-10-09 at 09:12 -0400, Nathan Nobbe wrote:
> On 10/7/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
> > Nothing brittle at all about PHP4 code. I can completely screw
> > up any PHP5 code you send my way too.
>
> ok;
> without modifying this class, set the value of $someInt to a value
> greater than
> 100 or less than 0.
> 
> class TryToViolateEncapsulation {
> private $someInt = 0;
> 
> public function getSomeInt() { 
>return $this->someInt;
> }
> 
> public function setSomeInt($someInt) {
> $success = false;  // assume failure
> $someInt = (int) $someInt;
> if($this->isValid($someInt)) { 
>   $this->someInt = $someInt;
>   $success = true;
> }
> 
> return $success;
> }
> 
> private function isValid($someInt) {
>$isValid = true;
>if($someInt < 0 || $someInt > 100) { 
>   $isValid = false;
>}
>return $isValid;
>}
> }

$sucker = new TryToViolateEncapsulation();
$sucker = (array)$sucker;
 
$keys = array_keys( $sucker );
$sucker[reset( $keys )] = 500;

$sucker = serialize( (object)$sucker );
$sucker = 'O:25:"TryToViolateEncapsulation"'.substr( $sucker, 14 );
$sucker = unserialize( $sucker );

print_r( $sucker );

:::

Maybe next time you'll have a challenge for me ;) And don't whine about
how I achieved what I did.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] How to format CLI tabular data?

2007-10-09 Thread tedd

At 12:05 AM -0700 10/9/07, Jim Lucas wrote:

Daevid Vincent wrote:

Does PHP have any tools like this? I'd prefer not to pull in some PEAR
package or other bloat, but I'll take what I can get if it actually works
well. I was hoping there are some tips/tricks to show simple tabular data:
-snip-
notice basic things like alignment, length of data (as in 'tabs' 
won't work), etc.




Try this out


-snip- code

Jim:

Thanks for the code. I've altered it to display a table in a browser:

http://webbytedd.com/bbb/table/

Code is shown there.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>
> You are confusing member variables with local variables. Member variables
> are part of the object's data which need to be made available to the
> outside
> world. Local variables are internal to the function, and do not need to be
> made available to the outside world. Local variables are part of the
> implementation, member varables are not.


no im not confusing anything;
local variables are within the scope of the function; therefore they are
part of the function
implementation.
instance variables are part of the scope of a class instance, therefore they
are part of its
implementation.

"Implementation" means the act of changing data, therefore it means the code
> and not the data itself.


code is nothing w/o data to manipulate; what is an algorithm w/o data to
manipulate; it
simply would not exist.


>
> > it is also about client code not being able to  view and manipulate the
> > implementation.
> > if client code can access data that the implementation (as you define it
> > [not consisting of data])
> > uses, or relys upon, then the outcome of the implementation can be
> altered
> > by client code.
>
> Then surely if a programmer fucks things up in such a fashion it would
> become apparent during unit testing? Then the culprit can be soundly
> whipped
> until he lears NOT to fuck up.


or better yet; protect the  implementation so he wouldnt have to be whipped
in the
first place.

> that is a violation of encapsulation,
>
> I disagree.Encapsulation is the act of placing the data, and the
> operations
> which act upon that data, in the same object. A violation of encapsulation
> is therefore to put the data and its operations in more than one object.
> Encapsulation has absolutely nothing to do with how those objects are used
> (or abused).
>
> > which is precisely why data is part of the implementation,
> > and it needs to be concealed from client code to maintain the integrity
> of
> > the implementation.
> >
> > The fundamental concepts of OOP consist of nothing more than
> > encapsulation,
> >> inheritance and polymorphism. Data hiding, interfaces and all that
> other
> >> fancy stuff are irrelevant.
> >
> > youre missing out on like the last decade or so of oop.
>
> I am sticking to the fundamentals and deliberately ignoring all the crap
> which has been added on by everybody and his dog.


hmm; the rest of the oop community seems to be flocking to the crap.

>>>im not going to take the
> >>> time to try and explain the power of the interface construct.  imho,
> you
> >>> have a long way to
> >>> go before you can grasp the power of the mechanism.
> >>
> >> I have never seen any gain from using interfaces in PHP, only pain,
> >> therefore I refuse to use them. Yet what functinality I am losing? None
> >> whatsoever.
> >
> > not every system will benefit from interfaces.
> > it sounds like you dont fully understand the use of them; and i wont say
> > its
> > immediately obvious.
>
> If it is not obvious in the way that interfaces can provide benefits then
> they are useless as far as I am concerned. I have never seen ANY
> documentation which shows ANY benefits from using interfaces, so I simply
> do
> not see the point in using them.
>
> > as i said they offer an additional polymorphic mechanism
> > one that php4 doesnt supply.
>
> I can achieve all the polymorphism I need WITHOUT using interfaces, so I
> do
> not see the point in using them.


like i said not every system will benefit.

> if you want a great example of how they are used and when extension is not
> > desirable (because the behavior is passed along) read the first chapter
> of
> > heads first design patterns.
>
> I refuse to read any more books on design patterns. In my opinion they are
> abused, over-used and over-rated. Just because one or two design patterns
> use interfaces does not mean that interfaces are the best thing since
> sliced
> bread.


it would be nice if you saw just one example why they are sometimes better
than
inheritance and therefore useful.

>>> in summary, i still maintain, based upon the contents of this post and
> >>> the
> >>> many previous posts
> >>> that sitting down and trying to learn oop with php4 is a waste of
> time.
> >>
> >> I strongly disagee. It *IS* possible to write perfectly adequate OO
> >> programs
> >> using PHP 4. If you cannot then you have been taught some bad habits.
> >
> >
> > actually, im trying to illustrate  bad habits so they may be avoided by
> > other developers.
> >
> > That is just your opinion. My opinion is totally different.
> >
> >
> > thats why i gave an alternate critique based upon your definition of
> > encapsulation.
> >
> > also, i should mention its occurred to me that the abstract class
> > mechanism
> > in php5 is superior to your mechanism in php4.
> > if a method marked as abstract in php5 is not overridden by client code,
> > an
> > error is raised at
> > compile time, and the class is  not allowed t

Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
>
> On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
> >
> >
> > Then how come these languages still offer PUBLIC access as an option?
>
>
>
> to expose a well defined interface of course.
>
> -nathan
>

and i have a question for you, Tony;
are variables local to a function not part of the function implementation?
i would say they are.  and in that light it is understandable, even
believable that class member variables comprise the implementation of the
class, no ?

-nathan


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/9/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>
>
> Then how come these languages still offer PUBLIC access as an option?



to expose a well defined interface of course.

-nathan


Re: [PHP] How to format CLI tabular data?

2007-10-09 Thread Richard Heyes

Daevid Vincent wrote:

I write many CLI scripts in PHP to clean up DB records, etc via crontab
scripts. Often though, I implement command line switches to 'debug' or see
various data as a precaution before actually purging.

Perl has some neat tools built in to format tabular data:
http://www.usenix.org/publications/perl/perl08.html

Does PHP have any tools like this?


The PEAR class Console_Table will do this for you.


I'd prefer not to pull in some PEAR
package or other bloat


PEAR does not automatically mean bloat. It does however automatically 
mean less work for you.


--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Tony Marston

""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On 10/7/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
>>
>> >  it just so happens i
>> > have a good friend with a very strong php background who tells me
>> > practically the same thing, ppp isnt that big of a deal.
>>
>> It isn't.
>
> i disagree.

And I disagree with you. Marking variables, or even methods, as anything 
other than public is purely OPTIONAL. If it were a requirement then the 
"public" keyword simply would not exist.

>> i disagree, why,
>> > is it because ive had a classical education in oop
>>
>> What the heck is a classical education in OOP? Are you saying your old
>> and therefore smarter? Young and therefor smarter? WTF?
>
> just saying i studied oop in college.  i started w/ c++; moved on to java
> and then took a brief look
> at .net and delphi (very brief :))  anyway coming from those languages to
> php4,

Just because it is what you were taught does not necessarily make it the 
gospel truth. Different teachers teach different things, and they cannot all 
be right.

> well php4 looks minimalistic.
> age has nothing to do with it; i provided 4 definitions from 4 books
> on oop; they all conicide w/ what ive been saying about encapsualtion;
> infact they practically
> say encapsulation is data hiding.
> i would like to see an example of encapsulation where data hiding isnt
> required to conceal the implementation.

Encapsulation is NOT data hiding. Take a look at

http://www.javaworld.com/javaworld/jw-05-2001/jw-0518-encapsulation.html
http://www.itmweb.com/essay550.htm
http://c2.com/cgi/wiki?EncapsulationIsNotInformationHiding

Encapsulation is about *implementation* hiding and implementation is *code*, 
not *data*. Data is information, and encapsulation does NOT mean 
*information hiding.

>>> because ive worked with
>>> a number of languages that dont allow you to create class members
>>> without specifying an access level?
>>
>> Many of us have done this. Your point?
>
> php4 is the first language i encountered that didnt offer ppp.

So what? PHP is the first language I have use in the past 30 years which 
supported OOP. None of the languages I have *ever* used have supported the 
notion of private or protected access - apart from the permissions system in 
the underlying database, of course.

I have learned to program without PPP, so I do not see any signifcant 
advantage in using it.

>>>  for those reasons and because ive had the
>>> misfortune of working in places that have tightly coupled code.  im
>>> talking about hundreds of thousands of lines of madness.  ppp could have
>>> saved these systems greatly.
>>
>> Once again, just because someone writes bad programs doesn't make PPP
>> the superior choice. A shitty programmer faced with PPP will more than
>> likely declare all of their member variables as public and as such will
>> have gained nothing.
>>


>> (tony)
 I strongly disagree. It *IS* possible to write perfectly adequate OO
 programs using PHP 4. If you cannot then you have been taught some bad 
 habits.
>>
>> Hear hear.
>
> on the contrary, im trying to emphasize what i have learned to be bad 
> habits
> so others
> might not use them in the first place.  one of which i have mentioned
> is allowing direct access to class members.  and i was never taught to do
> that, because as
> i mentioned, i worked with languages that require use of ppp in the past,
> and one of the first
> things thats covered is marking member variables private, and certain 
> member
> functions of course.

Just because YOU were taught to always make variables private does not mean 
that everybody else should do the same. A competent programmer can produce 
perfectly functional programs without using ppp at all, so it is not 
necessary.



> again; all the books ive ever read on oop, show class member variables 
> being
> marked private.

So what? None of the books or articles I have ever read on OOP have shown 
any such thing. They simply point out where it MAY be used to stop an 
incompetent programmer from screwing things up, but whatever obstacles you 
put in their way will only cause them to find other ways to screw up.

> also, they emphasize protecting certain methods as well.  php4 doesnt 
> offer
> ppp, so it opens
> the door to bad habits.

In your opinion.

> you can however protect your underlying codebase from misuse.  how 
> practical
> is it to get a company that consists entirely of excellent programmers?

It is simply not possible to protect ANY program from misuse. As soon as 
someone thinks that they have made something idiot proof the universe 
esponds by creating a better class of idiot.

>> ive studied oop for years and worked with a number of oop languages; many
>> of
>> > the bad habits i had at one point or another have been removed.  guess
>> what
>> > the first one was, not letting client code access member variables
>> directly

Then how come these languages still offer PU

Re: [PHP] Chmod a Directory

2007-10-09 Thread Daniel Brown
On 10/9/07, Stut <[EMAIL PROTECTED]> wrote:
> abderrazzak nejeoui wrote:
> > Please how can i chmod a directory to 0777
> > i tried chmod ($myDirectory, 0777); but nothing happens
>
> Check the return value. If it's false then it's failing for some
> reason., most likely because the user it's running as doesn't have
> permission to extend the permissions on that directory that far.
>
> Also make sure you read the notes here: http://php.net/chmod
>
> -Stut
>
> --
> http://stut.net/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Once again, Stut is most likely correct.  Chances are the
directory was created by someone other than as whom the script is
being run.  If you're server isn't configured to use phpSuExec, sticky
bits, or a similar setup, then chances are that you created the
directory as your user account (via FTP, SSH, a file manager, etc.),
and are attempting to chmod() the directory as Apache's user (nobody,
httpd, daemon, apache, etc.).

If that's the case, your best bet is to remove the directory using
the same medium with which you created it (if you can), and add the
following above your chmod() line:



However, another point to keep in mind is that, if you do things
correctly, you should never need a directory to be 0777 (everyone can
read, write, and execute), as that's a serious potential security
risk.

-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

Give a man a fish, he'll eat for a day.  Then you'll find out he was
allergic and is hospitalized.  See?  No good deed goes unpunished

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



Re: [PHP] Sending lots of emails - 2 choices - choose the best one

2007-10-09 Thread marek

The other possible question you might want to ask is:

How will the message be formatted and sent... some services such as 
hotmail will flag the message as spam based on the multiple mail 
deliveries when used option #2. And there are also many other 
considerations related to spam.

Instead what you could consider doing:
Option #3)
Write a subroutine that would group recipients based on host, and send 
one mail to each host with bcc. Also I would not use the internal mail 
function, instead I would try a full smtp class, especially when using 
mime that has built in support for services such as hotmail, yahoo, etc. 
Whenever we send email list to hotmail users I format the message 
differently then when we send to yahoo, and so on  I would avoid 
allowing sendmail to handle the function of grouping ...


Hope it helps...

Marek

Philip Thompson wrote:

On 10/7/07, Stut <[EMAIL PROTECTED]> wrote:
  

Martin Zvarík wrote:


Hello--
   I want to send email to 100+ recipients. Two choices I thought of:

1) once call mail() and use BCC, but the negative of this method is that
every recipient in BCC has header "To" same (so I used to put my email
in here - not email of one of the recipients).

2) several calls to mail() function with each recipient's emal
  

Why are you sending mail to 100+ recipients? Is it something you do
often? Is it always the same recipients? When are you sending them?

If it's a mailing list use mailing list software as Daevid suggested -
it's what it's for!

I would recommend avoiding the use of BCC from PHP.

-Stut





Why avoid Bcc from PHP?

~Philip

  


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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
wow, this thread has blown into a massive debate about oop.
well, i guess im the only one on the list who doesnt think php4 brings
enough to the table with its oop offerings.
the conversation has taken focus on what encapsulation is or isnt, but
recall, i pointed out there are many advantages php5 has.  i just think ppp
is one of the major features, if not the major feature that php4 lacks that
makes me shy away from it.
im not the only one who feels this way; i just must be the only one on the
list
who cares to say anything about it.  well here is an excerpt from the source
of code igniter, a popular open source php framework written in both php4
and
php5.

/**
 * CI_BASE - For PHP 4
 *
 * This file is used only when CodeIgniter is being run under PHP 4.
 *
 * In order to allow CI to work under PHP 4 we had to make the Loader class
 * the parent of the Controller Base class.  It's the only way we can
 * enable functions like $this->load->library('email') to instantiate
 * classes that can then be used within controllers as $this->email->send()
 *
 * PHP 4 also has trouble referencing the CI super object within application
 * constructors since objects do not exist until the class is fully
 * instantiated.  Basically PHP 4 sucks...
 *
 * Since PHP 5 doesn't suffer from this problem so we load one of
 * two files based on the version of PHP being run.
 *
 * @packageCodeIgniter
 * @subpackagecodeigniter
 * @categoryfront-controller
 * @authorRick Ellis
 * @linkhttp://www.codeigniter.com/user_guide/
 */

-nathan


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/7/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
> On Sun, 2007-10-07 at 11:42 +0100, Tony Marston wrote:
> >
> > The definition of OOP is "programming which is oriented around objects,
> thus
> > taking advantage of Encapsulation, Polymorphism, and Inheritance to
> increase
> > code reuse and decrease code maintenance". It is possible to do this in
> PHP
> > 4 without all the fancy add-ons which appeared in PHP 5. How do I know?
> > Because I have written an entire framework using objects in PHP 4, and
> the
> > result is high code reuse and low maintainence. There are no additional
> OO
> > features in PHP 5 which could deliver any measurable improvements.


not all systems will stand to gain from the features in php5.  but  ppp is a
very important  feature;
i would say any code that is not using  ppp could stand to benefit from it.
the interface construct is in my opinion the biggest enhancement to the php5
oop feature set, as
it offers a new avenue for polymorphic code.

>
> > >  any oo php4 'program' is inherently
> > > weak for the reasons i have sighted, namely the implementation can be
> > > latched onto producing tightly coupled code.
> >
> > Coupling is the degree of interaction between two modules. Low levels of
> > coupling tend to create code which is more reusable, whereas high levels
> of
> > coupling tend to create code which is less reusable. Coupling is
> therefore
> > directly related to reusability. Making all variables private does not
> *in
> > itself* make the code more reusable, therefore it does not make the code
> > more "coupled" or less "coupled".


all i said is that it prevents client code from becoming dependent upon
implementation
details, which doesnt reduce reusability, but does make the code difficult
to change
because at that point the client code needs to be changed as well.

Well, Nathan is assuming that if you have a public member that you
> probably didn't provide get/set wrappers for it. As such directly using
> the member variable does indeed increase the couple of your code to that
> module because if the variable needs to change in some way it's not
> possible to change the behaviour across the board without updating all
> uses of the member variable.
>
> However, just because it's public doesn't mean it doesn't have a get/set
> wrapper and doesn't mean it should be used directly. Yes, using a
> private declaration enforces use of the get/set wrapper, but once again,
> documentation can make this point also and as such marking a member
> variable as private is just syntactic sugar.
>
> Strangely enough though, PHP5 provides the means to NOT provide get/set
> methods and still modify the behaviour of direct access to a member
> variable via the magic __get/__set methods. Therefore the coupling issue
> is pretty moot for PHP5 regardless of how the variable is accessed.


a class writer would have to use the __get and __ set methods in their class
to expose access to private members.  those methods are suitable for special
purposes and anyway client code cant use them if theyre not defined in a
class,
so i dont consider the coupling issue moot.

-nathan


Re: [PHP] Sending lots of emails - 2 choices - choose the best one

2007-10-09 Thread Daniel Brown
On 10/9/07, Stut <[EMAIL PROTECTED]> wrote:
> Philip Thompson wrote:
> > On 10/7/07, Stut <[EMAIL PROTECTED]> wrote:
> >> I would recommend avoiding the use of BCC from PHP.
> >
> > Why avoid Bcc from PHP?
>
> Note that this applies to all automated sending, not just from PHP.
>
> It depends on how it's sending the mail. I've come across configurations
> where the first mail server it hits refuses to send it because there are
> so many BCC recipients.
>
> You are also more likely to fall foul of antispam systems because the To
> address is not the same as the address the recipient.
>
> IMHO the only legitimate use for BCC in an automated system is to have a
> copy sent to you for debugging/monitoring purposes.
>
> Of course this is just my experience-based opinion.
>
> -Stut
>
> --
> http://stut.net/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Also keep in mind that some buggy or misconfigured mail systems
have been known to forward the BCC data as an "X-Apparently-To" or
"Delivered-To" tag, even if the message is not 'apparently to' you.
In fact, I even used it years back in a honeypot server.  So if it's
important to keep those addresses private or transparent (though I
understand that it's not the issue in your case here), then that's
another reason to agree with Stut's point about shying away from BCC.

-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

Give a man a fish, he'll eat for a day.  Then you'll find out he was
allergic and is hospitalized.  See?  No good deed goes unpunished

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/6/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>
> Encapsulation and information hiding are separate topics. It is possible
> to
> have one without the other.


see the revision of my php4 critique.

> here are excerpts from 4
> > books, 2 on java, one on c++, and one on php:
> >
> > This abstraction works only if we are careful to respect its boundaries.
> > An
> > object should be self-governing, which means
> > that the variables contained in an object should be modified only within
> > the
> > object.  Only the methods within an object should
> > have access to the variables in that object.
>
> The principle of encapsulation has no such rule! Encapsulation is merely
> the
> act of placing variables and the methods which act upon those variables in
> the same object. It is not necessary to hide any variables.
>
> Encapsulation is NOT data hiding. Take a look at
>
> http://www.javaworld.com/javaworld/jw-05-2001/jw-0518-encapsulation.html
> http://www.itmweb.com/essay550.htm
> http://c2.com/cgi/wiki?EncapsulationIsNotInformationHiding
>
> >  For example, the methods of
> > the Coin class should be solely responsible for changing
> > the value of the face variable.  We should make it difficult, if not
> > impossible, for code outside of a class to "reach in" and change the
> > value of a variable that is declared inside the class.
> > Page 220. - 221
> > Java Software Solutions foundations of program design 3rd edition Lewis
> &
> > Loftus
> > The specification of what a function does and how it is invoked defines
> > its
> > interface.  By hiding a module implementation, or encapsulating
> > the module, we can make changes to it without changing the main
> function,
> > as
> > long as the interface remains the same.  For example, you
> > might rewrite the body of a function using a more efficient algorithm.
> > Encpasulation: Hiding a module implementation in a separate block with a
> > formally specified interface.
>
> The implementation is the CODE behind the method, not the DATA that the
> code
> manipulates. Encapsulation is IMPLEMENTATION hiding, not DATA hiding.


when variables store data needed to realize  the outcome of some method;
they
become part of the implementation and therefore should not be exposed to
client code.

> Page 354
> > Programming and Problem Solving with C++ Second Edition
> > Nell Dale, Chip Weems, Mark Headington
> >
> > OOP revolves around the concept of grouping code and data together in
> > logical units called classes.  This process is usually referred to as
> > encapsulation,
>
> Correct.
>
> > or information hiding,
>
> INCORRECT
>
> > since its goal is that of dividing an
> > application into separate entities whose internal components can
> > change without altering their external interfaces.
>
> No. The idea behind encapsulation is that the implementation, the code
> behind a method, can change at any time without the outside world being
> aware of it. Data is *NOT* the implemetation.
>
> > Page 113.
> > Zend PHP5 Certification Study Guide
> > Davey Shafik
> >
> > Access control is often referred to as implementation hiding.
>
> But wrongly! Access control is NOT implementation hiding, it is a totally
> separate issue.
>
> > Wrapping data
> > and methods within classes in combination with implementation
> > hiding is often called encapsulation4*
>
> That is correct. But only the implementation (the code behnd each method)
> is
> hidden, not the data.
>
> >  The result is a data type with
> > characteristics and behaviors.
> > * However, people often refer to implementation hiding alone as
> > encapsulation.
> > Page 231
> > Thinking in Java Third Edition
> > Bruce Eckel
> >
> >> tonight when i get home ill post
> >> > a  snippet from an entry level oop book (such that i recommend
> earlier)
> >> > that
> >> > says almost
> >> > verbatim what i have.
> >> >
> >> > practically any non-trivial class will have member variables that it
> >> uses
> >> > in
> >> > order to facilitate
> >> > its member functions.
> >>
> >> So what? Those variables do not have to be private or protected in
> order
> >> to
> >> function.
> >
> >
> > They dont have to be marked private or protected to function, but in
> order
> > to prevent
> > client code from latching onto the implementation details of the class;
> > they
> > need to be
> > hidden.
>
> Wrong! DATA does not define the implementation, it is the CODE which
> manipulates that data which defines the implementation. The idea of
> encapsulation is that you can change the code within any method at will
> without the outside world being aware of it.


it is also about client code not being able to  view and manipulate the
implementation.
if client code can access data that the implementation (as you define it
[not consisting of data])
uses, or relys upon, then the outcome of the implementation can be altered
by client code.
that is a violation of encapsulation, which is precisely why data is part of
the implementation,
and it ne

Re: [PHP] Something you can do with AJAX + PHP as well

2007-10-09 Thread Martin Zvarík

lame... you can use javascript (which is faster) for this kind of stuff

Mark napsal(a):

Hey,

I've made a nice video where you see ajax in combination with php. and
it works really well although really is misspelled "realy".

Here is the video:
http://magedb.mageprojects.com/videos/MageDB%202nd%20WIP%20demonstration%20with%20AJAX.mpeg

Cool huh?

Mark.

  


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



Re: [PHP] How to format CLI tabular data?

2007-10-09 Thread tedd

At 3:59 PM -0700 10/8/07, Daevid Vincent wrote:

I write many CLI scripts in PHP to clean up DB records, etc via crontab
scripts. Often though, I implement command line switches to 'debug' or see
various data as a precaution before actually purging.

Perl has some neat tools built in to format tabular data:
http://www.usenix.org/publications/perl/perl08.html

Does PHP have any tools like this? I'd prefer not to pull in some PEAR
package or other bloat, but I'll take what I can get if it actually works
well. I was hoping there are some tips/tricks to show simple tabular data:

i.e.:

# foo.php --showgroups

==
  Groups
==
Name: Expires: Date:
   ---
groupA3 hours   2007-10-08
groupBeta10 hours   2007-11-10
groupC1 week2007-12-31


notice basic things like alignment,
length of data (as in 'tabs' won't work), etc.


It's tabular -- why not use tables?

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Nathan Nobbe
On 10/7/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
> >  it just so happens i
> > have a good friend with a very strong php background who tells me
> > practically the same thing, ppp isnt that big of a deal.
>
> It isn't.


i disagree.

> i disagree, why,
> > is it because ive had a classical education in oop
>
> What the heck is a classical education in OOP? Are you saying your old
> and therefore smarter? Young and therefor smarter? WTF?


just saying i studied oop in college.  i started w/ c++; moved on to java
and then took a brief look
at .net and delphi (very brief :))  anyway coming from those languages to
php4,
well php4 looks minimalistic.
age has nothing to do with it; i provided 4 definitions from 4 books
on oop; they all conicide w/ what ive been saying about encapsualtion;
infact they practically
say encapsulation is data hiding.
i would like to see an example of encapsulation where data hiding isnt
required to conceal the
implementation.

> , because ive worked with
> > a number of languages that dont allow you to create class members
> without
> > specifying an access level?
>
> Many of us have done this. Your point?


php4 is the first language i encountered that didnt offer ppp.

>   for those reasons and because ive had the
> > misfortune of working in places that have tightly coupled code.  im
> talking
> > about hundreds of thousands of lines of madness.  ppp could have saved
> these
> > systems greatly.
>
> Once again, just because someone writes bad programs doesn't make PPP
> the superior choice. A shitty programmer faced with PPP will more than
> likely declare all of their member variables as public and as such will
> have gained nothing.
>
> > Also, don't forget that abstraction, encapsulation, and information
> > > hiding all have a price
> >
> > if youre referring to performance i think the price of not using these
> tools
> > is also worth mention.  namely code which is easily subject to tight
> > coupling, which as i said leads to systems that are difficult to
> maintain
> > and extend.
> > personally i value maintainability and extensibility over performance,
> but
> > thats merely a personal preference.
>
> Tell that to an embedded systems programmer.


ok.
embedded systems programmer -  i develop web applications w/ php.  i use oop
and build systems designed for large audiences and large numbers of
developers.
being able to extend, modify, and maintain the code are more important than
small
performance gains here and there; because i can always call dell for another
1u.

> (tony)
> > > I strongly disagree. It *IS* possible to write perfectly adequate OO
> > programs
> > > using PHP 4. If you cannot then you have been taught some bad habits.
>
> Hear hear.


on the contrary, im trying to emphasize what i have learned to be bad habits
so others
might not use them in the first place.  one of which i have mentioned
is allowing direct access to class members.  and i was never taught to do
that, because as
i mentioned, i worked with languages that require use of ppp in the past,
and one of the first
things thats covered is marking member variables private, and certain member
functions of
course.

> and what exactly does adequate mean?  any oo php4 'program' is inherently
> > weak for the reasons i have sighted, namely the implementation can be
>
> I'm sur eyou meant "cited" above.


yes

> latched onto producing tightly coupled code.
> > dont worry tony, i can construe some pretty decent php4 code myself; i
> wrote
> > a date time package that ive ported to 3 projects including a conversion
> to
> > php5 in one of those.  the point is that the other developers i work
> with
> > dont have a clue about object oriented concepts which in my experience
> > constitutes the vast majority of php developers.  the even bigger point,
> on
> > the topic of this thread is that php4 is out the door, so there is yet
> > another possibly more important reason not to waste time learning oop
> > studying php4.
>
> Once again, if you suck at programming you suck at programming. Those
> sucky programmers are probably going to declare all their member vars
> public, aren't going to understand encapsulation, probably will have
> terrible class hierarchies, etc. You can't make a good programmer by
> holding their hand.


again; all the books ive ever read on oop, show class member variables being
marked private.
also, they emphasize protecting certain methods as well.  php4 doesnt offer
ppp, so it opens
the door to bad habits.
you can however protect your underlying codebase from misuse.  how practical
is it
to get a company that consists entirely of excellent programmers?

> ive studied oop for years and worked with a number of oop languages; many
> of
> > the bad habits i had at one point or another have been removed.  guess
> what
> > the first one was, not letting client code access member variables
> directly
> > :)
>
> I've worked with many languages too. I found my code getting better
> wh

Re: [PHP] Structure of maintainable websites

2007-10-09 Thread Richard Heyes
So, my question is: are there any good practices that I should be aware 
of or example websites I can study, that will give me the knowledge I 
need? I'm not looking for references on general software design 
approaches, but practical information on how to apply them to PHP websites.


You could do worse than looking at this:

http://www.phpguru.org/static/ApplicationStructure.html

Lots of people like to over complicate their structure, but this (I 
find) usually suffices. Plus it's easy to navigate and interpret.


PS. Smarty has nothing to do with structure - it's got everything to do 
with needlessly reducing performance.


--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

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



Re: [PHP] Chmod a Directory

2007-10-09 Thread Stut

abderrazzak nejeoui wrote:

Please how can i chmod a directory to 0777
i tried chmod ($myDirectory, 0777); but nothing happens


Check the return value. If it's false then it's failing for some 
reason., most likely because the user it's running as doesn't have 
permission to extend the permissions on that directory that far.


Also make sure you read the notes here: http://php.net/chmod

-Stut

--
http://stut.net/

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



Re: [PHP] Sending lots of emails - 2 choices - choose the best one

2007-10-09 Thread Stut

Philip Thompson wrote:

On 10/7/07, Stut <[EMAIL PROTECTED]> wrote:

I would recommend avoiding the use of BCC from PHP.


Why avoid Bcc from PHP?


Note that this applies to all automated sending, not just from PHP.

It depends on how it's sending the mail. I've come across configurations 
where the first mail server it hits refuses to send it because there are 
so many BCC recipients.


You are also more likely to fall foul of antispam systems because the To 
address is not the same as the address the recipient.


IMHO the only legitimate use for BCC in an automated system is to have a 
copy sent to you for debugging/monitoring purposes.


Of course this is just my experience-based opinion.

-Stut

--
http://stut.net/

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



Re: [PHP] Chmod a Directory

2007-10-09 Thread Samuel Vogel
You will have to loop through the directory recursively, running chmod() 
on every file there is!


Regards,
Samy

abderrazzak nejeoui schrieb:

Please how can i chmod a directory to 0777
i tried chmod ($myDirectory, 0777); but nothing happens
thanks in advence

Nejeoui

  


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



[PHP] Chmod a Directory

2007-10-09 Thread abderrazzak nejeoui
Please how can i chmod a directory to 0777
i tried chmod ($myDirectory, 0777); but nothing happens
thanks in advence

Nejeoui


Re: [PHP] php5 - possible bug discovered

2007-10-09 Thread Stut

David Restall - System Administrator wrote:

My main obesrvation is that I'm glad that I decided to revisit all my
old PHP4 stuff and rewrite or clean it up.  I have hundreds of

$Working_Class = $Under_Class;

lines in my code as well as

$Upper_Class = & $Aristocracy;

lines too.  I think the documentation on references needs updating to
reflect PHP 5's behaviour a little more accurately because I can see
this causing serious problems to somebody just copying their code blindly.


This change was made very clear in the changelog for PHP5. Whenever you 
change to a different PHP version the changelog should be the first 
thing you read. If you try to read the documentation to pick out the 
changes you'll miss something.


-Stut

--
http://stut.net/

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



Re: [PHP] php5 - possible bug discovered

2007-10-09 Thread David Restall - System Administrator
Hi Robert, Stut & List

Thanks for your replies which arrived after I had gone to bed |-Z

Robert :-

> In PHP5 objects are no longer copied when assigned. Instead the object's
> handle is assigned (similar to a reference but not quite). So the
> behaviour is as expected.

Stut :-

> > I think I have discovered a bug in php5.  If I haven't, I've discovered
> > a bug in the documentation or a bug in my brain.
> 
> Start here: http://php.net/language.oop5.cloning

It's amazing what a good night's sleep will do :-)

I could not find that page last night even though I was sure it must
have existed and I can see that it is a well documented and encountered
problem.

My main obesrvation is that I'm glad that I decided to revisit all my
old PHP4 stuff and rewrite or clean it up.  I have hundreds of

$Working_Class = $Under_Class;

lines in my code as well as

$Upper_Class = & $Aristocracy;

lines too.  I think the documentation on references needs updating to
reflect PHP 5's behaviour a little more accurately because I can see
this causing serious problems to somebody just copying their code blindly.

I have just built a client a development server using php5 instead of
php4 and turned zend.ze1_compatibility_mode on so that their old CMS would
work - I just hadn't realised that the cloning problem was solved by this.

Oh well, now I'm fresh I can crack on :-)

TTFN


D
php/general-2007-10-09.tx  [EMAIL PROTECTED]
   [EMAIL PROTECTED]
   php-general
++
| Dave Restall, Computer Nerd, Cyclist, Radio Amateur G4FCU, Bodger  |
| Mob +44 (0) 7973 831245  Skype: dave.restall Radio: G4FCU  |
| email : [EMAIL PROTECTED] Web : Not Ready Yet :-(   |
++
| birth, n:  |
| The first and direst of all disasters. |
| -- Ambrose Bierce, "The Devil's Dictionary"|
++

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



Re: [PHP] How to format CLI tabular data?

2007-10-09 Thread Jim Lucas

Daevid Vincent wrote:

I write many CLI scripts in PHP to clean up DB records, etc via crontab
scripts. Often though, I implement command line switches to 'debug' or see
various data as a precaution before actually purging.

Perl has some neat tools built in to format tabular data:
http://www.usenix.org/publications/perl/perl08.html

Does PHP have any tools like this? I'd prefer not to pull in some PEAR
package or other bloat, but I'll take what I can get if it actually works
well. I was hoping there are some tips/tricks to show simple tabular data:

i.e.:

# foo.php --showgroups

==
  Groups
==
Name: Expires: Date:
   ---
groupA3 hours   2007-10-08
groupBeta10 hours   2007-11-10
groupC1 week2007-12-31


notice basic things like alignment, 
length of data (as in 'tabs' won't work), etc.




Try this out

$row) {
foreach($row AS $column => $value) {
  $columnWidths[$column] = max(strlen($value), 
@$columnWidths[$column]);

}
  }
  $totalWidth  = 0;
  foreach($columnWidths AS $length) {
$totalWidth += ($length+$seperation);
  }
  echo str_pad('', ($totalWidth+count($columnWidths)), $seperator)."\n";
  foreach($columnWidths AS $header => $length) {
echo ' '.str_pad($header, ($length+$seperation), ' ');
  }
  echo "\n".str_pad('', ($totalWidth+count($columnWidths)), 
$seperator)."\n";

  foreach($data AS $header=>$row) {
foreach($row AS $column => $value) {
  echo ' '.str_pad($value, ($columnWidths[$column]+$seperation));
}
echo "\n";
  }
  echo str_pad('', ($totalWidth+count($columnWidths)), $seperator)."\n";
}

displayFixedWidth($data);
--
Jim Lucas


"Perseverance is not a long race;
it is many short races one after the other"

Walter Elliot



"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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