[PHP] Re: Classes and Functions

2009-12-28 Thread Daniel Kolbo
Nathan Rixham wrote:
> Daniel Kolbo wrote:
>> Hello,
>>
>> Is there a way to see what objects and functions a script
>> loaded/required/used?
>>
>> I could recursively loop through the globals, but if objects were unset,
>> then i may miss some.
>>
>> I could make a 'tracking' object and every time i load/include a file
>> (which contains a class def or a function def) to add that file to the
>> tracking object...but it would be nice if i didn't have to modify my
>> existing code to see which objects and functions a script actually used,
>> or at least, requested and loaded into memory.
>>
>> Thanks in advance,
>> Daniel Kolbo
>> `
>>
> 
> if it's for debugging, get a good debugger so you can inspect at break
> points; for use during runtime and something "scripted" you can call the
> relevant get_defined/declared functions before before your app does it's
> loading, then the same later on and compare to get a definitive list.
> 
> also worth asking if you're refering to objects (as in instances) or
> classes.
> 
> Object = instance of a Class [ $object = new Class() ]
> 
Hello Mr. Rixham,

Thanks for the reminder about those 'get' functions.  (just what i was
looking for).

Thanks,
dK
`

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



[PHP] Re: Classes and Functions

2009-11-04 Thread Nathan Rixham

Daniel Kolbo wrote:

Hello,

Is there a way to see what objects and functions a script
loaded/required/used?

I could recursively loop through the globals, but if objects were unset,
then i may miss some.

I could make a 'tracking' object and every time i load/include a file
(which contains a class def or a function def) to add that file to the
tracking object...but it would be nice if i didn't have to modify my
existing code to see which objects and functions a script actually used,
or at least, requested and loaded into memory.

Thanks in advance,
Daniel Kolbo
`



if it's for debugging, get a good debugger so you can inspect at break 
points; for use during runtime and something "scripted" you can call the 
relevant get_defined/declared functions before before your app does it's 
loading, then the same later on and compare to get a definitive list.


also worth asking if you're refering to objects (as in instances) or 
classes.


Object = instance of a Class [ $object = new Class() ]

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



Re: [PHP] Re: Classes in PHP5 || Puzzling Problem || Trying to Set $this->$name = $value

2007-03-09 Thread PHP
Hey Stu.

Well, isn't that special ;--)

Jesus, I kept echoing $this->$foo within the parent class and getting 0, 
instead of 1.

You wrote your reply; I checked the results again, and, voila, it worked --  
obviously I must have been missing something and corrected the mistake in my 
endless trial and error process, lol.

In any case, thanks for sorting me out!

-Noah



"Stut" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> PHP wrote:
>> Problem:
>>
>> Class test {
>>
>> var $foo = 0;
>>
>> function __construct() {
>> $this->myfunc("foo", 1);
>> }
>>
>> function myfunc($name, $val) {
>> $this->$name = $val;
>> }
>> }
>>
>> Now, PHP correctly evaluates $this->$name as 0; i.e. the default property 
>> value of $this->foo.
>>
>> However, what I really need to have happen is for $this->$name = $val to 
>> be evaluated as $this->foo = 1;
>
> Works fine here: http://dev.stut.net/php/classvar.php
>
> What do you get?
>
> -Stut 

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



Re: [PHP] Re: Classes in PHP5 || Puzzling Problem || Trying to Set $this->$name = $value

2007-03-08 Thread Frank M. Kromann
Sounds like a PHP version problem. PHP 4 will output 0 and PHP 5 will give
1. The constructor must be named the same as the class name in PHP 4 for
this to work.

You can have both constructors in your class so it will work in both
versions.

- Frank

> I don't know the details of your app, but you might want to reconsider a
resdesign.  
> 
> Having said that, your code actually works for me.  If I use your class
as is, foo is 1.  That is:
> 
> $x = new test;
> echo $x->foo;
> 
> outputs 1.  Isn't that what you want?
> 
> 
> 
> Regards,
> 
> Bruce
> 
> >>> "PHP" <[EMAIL PROTECTED]> 9/03/2007 6:10:49 p.m. >>>
> Hey all.
> 
> Problem:
> 
> Class test {
> 
> var $foo = 0;
> 
> function __construct() {
> $this->myfunc("foo", 1);
> }
> 
> function myfunc($name, $val) {
> $this->$name = $val;
> }
> }
> 
> Now, PHP correctly evaluates $this->$name as 0; i.e. the default
property 
> value of $this->foo.
> 
> However, what I really need to have happen is for $this->$name = $val to
be 
> evaluated as $this->foo = 1;
> 
> I have tried variations of $this->$$name = $val, $this->${$name} = $val,

> etc., but none of them work -- I keep getting an "Undefined variable:
foo" 
> error from PHP, when very clearly foo has been defined.
> 
> This is a very simple example of what I'm actually attempting to
implement, 
> so please do not reply with, "Well, why not just do: $this->foo = $val"
> 
> I'm sure intermediate to advanced PHP developers have run across this
issue 
> before -- feel free to chime in ;--)
> 
> Thanks!
> 
> --Noah 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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



Re: [PHP] Re: Classes in PHP5 || Puzzling Problem || Trying to Set $this->$name = $value

2007-03-08 Thread Stut

PHP wrote:

Problem:

Class test {

var $foo = 0;

function __construct() {
$this->myfunc("foo", 1);
}

function myfunc($name, $val) {
$this->$name = $val;
}
}

Now, PHP correctly evaluates $this->$name as 0; i.e. the default property 
value of $this->foo.


However, what I really need to have happen is for $this->$name = $val to be 
evaluated as $this->foo = 1;


Works fine here: http://dev.stut.net/php/classvar.php

What do you get?

-Stut

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



[PHP] Re: Classes in PHP5 || Puzzling Problem || Trying to Set $this->$name = $value

2007-03-08 Thread Bruce Cowin
I don't know the details of your app, but you might want to reconsider a 
resdesign.  

Having said that, your code actually works for me.  If I use your class as is, 
foo is 1.  That is:

$x = new test;
echo $x->foo;

outputs 1.  Isn't that what you want?



Regards,

Bruce

>>> "PHP" <[EMAIL PROTECTED]> 9/03/2007 6:10:49 p.m. >>>
Hey all.

Problem:

Class test {

var $foo = 0;

function __construct() {
$this->myfunc("foo", 1);
}

function myfunc($name, $val) {
$this->$name = $val;
}
}

Now, PHP correctly evaluates $this->$name as 0; i.e. the default property 
value of $this->foo.

However, what I really need to have happen is for $this->$name = $val to be 
evaluated as $this->foo = 1;

I have tried variations of $this->$$name = $val, $this->${$name} = $val, 
etc., but none of them work -- I keep getting an "Undefined variable: foo" 
error from PHP, when very clearly foo has been defined.

This is a very simple example of what I'm actually attempting to implement, 
so please do not reply with, "Well, why not just do: $this->foo = $val"

I'm sure intermediate to advanced PHP developers have run across this issue 
before -- feel free to chime in ;--)

Thanks!

--Noah 

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

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



[PHP] Re: Classes in PHP5 || Puzzling Problem || Trying to Set $this->$name = $value

2007-03-08 Thread PHP
Hey all.

Problem:

Class test {

var $foo = 0;

function __construct() {
$this->myfunc("foo", 1);
}

function myfunc($name, $val) {
$this->$name = $val;
}
}

Now, PHP correctly evaluates $this->$name as 0; i.e. the default property 
value of $this->foo.

However, what I really need to have happen is for $this->$name = $val to be 
evaluated as $this->foo = 1;

I have tried variations of $this->$$name = $val, $this->${$name} = $val, 
etc., but none of them work -- I keep getting an "Undefined variable: foo" 
error from PHP, when very clearly foo has been defined.

This is a very simple example of what I'm actually attempting to implement, 
so please do not reply with, "Well, why not just do: $this->foo = $val"

I'm sure intermediate to advanced PHP developers have run across this issue 
before -- feel free to chime in ;--)

Thanks!

--Noah 

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



[PHP] Re: classes and objects: php5. The Basics

2007-01-16 Thread Daniel Kullik

Cheseldine, D. L. wrote:

Hi

I'm stuck on The Basics page of the php5 Object Model:

http://uk.php.net/manual/en/language.oop5.basic.php

The top example has the code:

A::foo();

even though foo is not declared static in its class.  How does it get
called statically without being declared static?

regards
dave


Hi Dave,

the example code seems to be damn old. It doesn't even make use of the
access control modifiers.

To answer your question: foo() can be called statically this way since 
PHP5 still supports the PHP4-way of calling static methods 
(backwards-compatibility). In PHP4 one can call any method statically, 
since there is no "static" modifier in PHP4.


Hint: In this case PHP5 generates an error of the type E_STRICT, which 
tells you that one can't call a given instance method statically.


error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'on');


Regards,
Daniel

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



[PHP] Re: Classes or functions

2005-10-22 Thread Oliver Grätz
I'd say it depends on the size of your project and on any plans to reuse
the code. Classes are better suited for building libraries of code you
use in other projects. And any large project runs into problems with
function names if the programmer doesn't use a rigorous naming system
(like "function package_subpackage_functionname() { ... }") and if such
names are used one could just as good use classes.

Technical difference: Functions are a little bit faster (think of PHP
having to look just one time instead of one time for findeing the class
and one time for finding the method).

Depending on PHP version: PHP4 has an affinity to using functions
because the classes are not as mature and full-featured as in PHP5.
So: with PHP4, you actively have to choose using classes;
with PHP5, you want to use classes.

OLLi

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



[PHP] Re: Classes code completion and Zend Studio

2005-03-14 Thread Jamie Alessio
I have a function to load the classes and return the object.
function LoadClass($ClassName)
{
require_once("Class.$ClassName.inc");
return new $ClassName();
}
Its working fine.
But Zend Studio's Code completion is not working for this type of
object, Any hints?
Zareef,
In Zend Studio 4.0 (not sure about earlier versions) you can use a 
"class type hint" to let the editor know what type of object you are 
working with. This is especially useful when you are using factory 
methods to create objects (as I often do with PEAR DataObjects) or have 
a setup similar to the above. The documentation for this in the studio 
distribution appears to be broken because it says something like "See 
below for example" but there is actually no example (I filed a bug with 
Zend about this). Butm, if you dig through he "Quick Tips" you can find 
the example which is where I first came across it.

Here's how I use it for DataObjects:
--
$user_obj =& DB_DataObject::factory('User');
/* @var $user_obj DataObjects_User */
$user_obj->youShouldHaveCodeCompletionNowForThisObject();
--
In your example it would be something like:
--
$user_obj = LoadClass('user');
/* @var $user_obj user */
$user_obj->youShouldHaveCodeCompletionNowForThisObject();
--
You'll need to make sure that Zend Studio knows to look through the file 
that contains the class that you are dynamically loading. I think you 
can do this if your code is withint a "project" and you specify it with 
"Add to Project".

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


[PHP] Re: Classes code completion and Zend Studio

2005-03-14 Thread Zareef Ahmed
On Mon, 14 Mar 2005 10:28:06 -0800, Jamie Alessio
<[EMAIL PROTECTED]> wrote:
> > I have a function to load the classes and return the object.
> >
> > function LoadClass($ClassName)
> > {
> > require_once("Class.$ClassName.inc");
> > return new $ClassName();
> > }
> >
> > Its working fine.
> >
> > But Zend Studio's Code completion is not working for this type of
> > object, Any hints?
> >
> Zareef,
> In Zend Studio 4.0 (not sure about earlier versions) you can use a
> "class type hint" to let the editor know what type of object you are
> working with. This is especially useful when you are using factory
> methods to create objects (as I often do with PEAR DataObjects) or have
> a setup similar to the above. The documentation for this in the studio
> distribution appears to be broken because it says something like "See
> below for example" but there is actually no example (I filed a bug with
> Zend about this). Butm, if you dig through he "Quick Tips" you can find
> the example which is where I first came across it.
> 
> Here's how I use it for DataObjects:
> --
> $user_obj =& DB_DataObject::factory('User');
> /* @var $user_obj DataObjects_User */
> $user_obj->youShouldHaveCodeCompletionNowForThisObject();
> --
> 
> In your example it would be something like:
> --
> $user_obj = LoadClass('user');
> /* @var $user_obj user */
> $user_obj->youShouldHaveCodeCompletionNowForThisObject();
> --

Yes Jamie  It works.
Thanks a lot 

zareef ahmed 
> 
> You'll need to make sure that Zend Studio knows to look through the file
> that contains the class that you are dynamically loading. I think you
> can do this if your code is withint a "project" and you specify it with
> "Add to Project".
> 
> - Jamie
> 
> 


-- 
Zareef Ahmed :: A PHP Developer in India ( Delhi )
Homepage :: http://www.zareef.net

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



Re: [PHP] Re: Classes and parents.

2005-01-22 Thread M. Sokolewicz
Jochem Maas wrote:
Dmitry wrote:
Thanks,
but I think that this code more easy.
class a {
 function say() { echo "A"; }
 function run() { $this->say(); }
}
class b {
 function say() { echo "B"; }
 function run() {
$a = new a;
$a->run();

for starters b doesn't even extend a
and secondly the b::run() method is creating an object
on each invocation - not exactly good use of OO.
besides which b::run() is creating an object of an arbitrary
class, assuming b was supposed to extend a in your example above
the you have hardcoded the parent into the subclass, thats plain wrong...
my example wasn't a specific solution to your problem but an example of 
3 ways to acomplish the goal of calling the version of a method in the 
super class. if you didn't understand something just ask.

}
}
$obj = new b;
$obj->run();
class a {
   function say() { echo "A"; }
   function run() { self::say(); }
}
class b {
   function say() { echo "B"; }
   function run() {
  parent::run();
   }
}
would work fine though, I think :)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: Classes and parents.

2005-01-22 Thread Jochem Maas
Dmitry wrote:
Thanks,
but I think that this code more easy.
class a {
 function say() { echo "A"; }
 function run() { $this->say(); }
}
class b {
 function say() { echo "B"; }
 function run() {
$a = new a;
$a->run();
for starters b doesn't even extend a
and secondly the b::run() method is creating an object
on each invocation - not exactly good use of OO.
besides which b::run() is creating an object of an arbitrary
class, assuming b was supposed to extend a in your example above
the you have hardcoded the parent into the subclass, thats plain wrong...
my example wasn't a specific solution to your problem but an example of 
3 ways to acomplish the goal of calling the version of a method in the 
super class. if you didn't understand something just ask.

}
}
$obj = new b;
$obj->run();
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Classes and parents.

2005-01-22 Thread Dmitry
Thanks,
but I think that this code more easy.

class a {
 function say() { echo "A"; }
 function run() { $this->say(); }
}
class b {
 function say() { echo "B"; }
 function run() {
$a = new a;
$a->run();
}
}

$obj = new b;
$obj->run();

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



[PHP] Re: Classes and Interface tool

2004-10-27 Thread Jason Barnett
Jonel Rienton wrote:
hi again guys, is there a tool that can allow you view the available
interfaces of a class, like an object/class browser that can help you view
the signatures of those interfaces?
thanks and regards,
Jonel

You should be able to use the Reflection API to find out what you want to know 
about Interfaces.  Specifically, you can use

ReflectionClass::export('nameOfYourInterface');
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Re: Classes, instances and NULL

2004-07-29 Thread Michael Sims
Oliver Hitz wrote:
> Thank you. I know there is a `===' operator, but to me this doesn't
> make sense either.
>
>   class A { }
>   class B { var $x; }
>
> It is logical that an instance of `A' is not identical to null.
> However, why is an instance of `A' equal (`==' operator) to null, an
> instance of `B' not? Do objects automatically evaluate to their
> associative array representation? Is this intended behaviour?

There are four different types that PHP could be casting the object and null to that
would result in them being equal, namely boolean, integer, float, and array.  It's
definitely not casting them to string or object.  My guess is the behavior is not
intentional since the documentation for the "NULL" type says that a variable is
equal to null only if it has had the "null" constant assigned to it, it has not had
a value assigned to it at all, or it has been unset().  You'd probably get more
definitive answers on the internals list.  Personally I consider the behavior a bug,
so I'd probably file a bug report on it, although I wouldn't expect it to be given a
high priority. :)


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



Re: [PHP] Re: Classes, instances and NULL

2004-07-29 Thread Oliver Hitz
On 29 Jul 2004, Mehdi Achour wrote:
> Hi Oliver, you should test with === instead of ==
>   http://php.net/manual/en/language.operators.comparison.php

Thank you. I know there is a `===' operator, but to me this doesn't make
sense either.

  class A { }
  class B { var $x; }

It is logical that an instance of `A' is not identical to null. However,
why is an instance of `A' equal (`==' operator) to null, an instance of
`B' not? Do objects automatically evaluate to their associative array
representation? Is this intended behaviour?

Thanks
Oliver


pgpA5YT2eDqch.pgp
Description: PGP signature


[PHP] Re: Classes, instances and NULL

2004-07-29 Thread Mehdi Achour
Hi Oliver, you should test with === instead of ==
  http://php.net/manual/en/language.operators.comparison.php
didou
Oliver Hitz wrote:
Hi all,
I have stumbled across something odd related to classes, instances and
NULL in PHP 4. Apparently, an instance of a class that doesn't contain
any variables is always equal to NULL.
  class MyClass {
function anyFunction() {
  ...
}
  }
  $c = new MyClass();
  if ($c == null) {
print "is \$c really null?";
  }
`is_null($c)' however, returns `false', as one would expect.
As soon as the class contains a variable, the `$c == null' comparison
returns false.
Is there any logical reason why the comparison with the `==' operator
returns `true'? I don't know about the internals of PHP, but I think
this might be related to implementation details (e.g. instances of
classes being associative arrays). However, from an OOP point of view
this behaviour seems rather weird.
I may not be the first to notice this. I couldn't find anything in the
mailing list, if there has already been a discussion about this, just
point me to the right direction.
Thanks
Oliver
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Classes

2003-07-25 Thread sven
do you get an error-message? which?
maybe you use
var $id = array();
instead of
var $id[];

ciao SVEN

Patrik Fomin wrote:
> I need to create a class that looks like this:
>
> class Artikel {
>  var $id[];
>  var $rubrik[];
>  var $ingress[];
>  var $kategori[];
>  var $frontbildtyp[];
>  var $frontbild[];
>  var $kategoribild[];
>  var $aktuell;
>
>  function SetId($id) {
>   $this->id[$this->aktuell] = $id;
>  }
>
>  function SetRubrik($id) {
>   $this->id[$this->aktuell] = $id;
>  }
>
>  function SetIngress($id) {
>   $this->id[$this->aktuell] = $id;
>  }
>
>  function SetKategori($id) {
>   $this->id[$this->aktuell] = $id;
>  }
>
>  function SetKategoriBild($id) {
>   $this->id[$this->aktuell] = $id;
>  }
>
>  function SetFrontbildtyp($id) {
>   $this->id[$this->aktuell] = $id;
>  }
>
>  function SetFrontbild($id) {
>   $this->id[$this->aktuell] = $id;
>  }
>
>  function SetNextPost() {
>   $this->aktuell++;
>  }
>
>  function SetStartPost() {
>   $this->aktuell = 0;
>  }
>
> }
>
>
> the problem is that php wont let me :/, any ideas?
>
> regards
> patrick



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



Re: [PHP] Re: classes v. functions

2003-07-20 Thread Robert Cummings
On Sun, 2003-07-20 at 02:28, Andu wrote:
> 
> One shouldn't apply industrial theories to just everything.
> 

Object Oriented Design is not an industrial theory. It's a tried and
true practice with over a decade of computer science and practical use
behind it. Procedural programming is a subset of Object oriented
programming. Someday you'll need the higher level features OOD offers,
but until then it probably just won't make sense unless you actually go
and learn the principles from a good book or teacher. Trying to
formulate an opinion about OOD from the PHP mailing list is like trying
to form an opinion about nuclear physics from your buddy that watched
some show on nuclear power plants (maybe not that extreme, but hopefully
you get the point).

Cheers,
Rob.
-- 
.-.
| Worlds of Carnage - http://www.wocmud.org   |
:-:
| Come visit a world of myth and legend where |
| fantastical creatures come to life and the  |
| stuff of nightmares grasp for your soul.|
`-'

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



Re: [PHP] Re: classes v. functions

2003-07-19 Thread Andu


--On Sunday, July 20, 2003 07:53:20 +0200 Simon Fredriksson 
<[EMAIL PROTECTED]> wrote:

I've been working like that for about two years and just recently I got
enlighted in the use of classes.
The main reason I started this thread is that since I'm just beginning with 
php I thought I might as well start with a good methodology. I've seen on 
the net whole collections of classes some going as far as almost inventing 
a new language but having some experience I know everything comes at a 
price.
Classes seem to provide advantages to plain functions but only sometimes, 
striking the right balance I guess, is what I'm after.
One shouldn't apply industrial theories to just everything.

Regards, Andu Novac

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


Re: [PHP] Re: classes v. functions

2003-07-19 Thread Curt Zirzow
* Thus wrote Simon Fredriksson ([EMAIL PROTECTED]):
> [...]
> just got confused. Then, suddenly I got some class for something, 
> checked out the code and my brain just snapped. "aaah, THAT's how it's 
> done!". It wasn't well documented, just nicely structured and easy to 
> read and understand.

I need a good brain snap sometimes, too :)


Curt.
--


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



Re: [PHP] Re: classes v. functions

2003-07-19 Thread Simon Fredriksson
I've been working like that for about two years and just recently I got 
enlighted in the use of classes. I've built a few sites and after a 
while on each of them I run into a problem. Say I wanna add a 
meta-refresh tag or send a cookie; with my earlier code, that brought 
out hell... more or less. Sure I solved it, but it never felt like it 
was the best thing to do.

Since I first used a class, I've tried to figure out how they work. I 
got them running but I had no idea what I did, I just used the examples 
provided. I read through some tutorial and the docs at php.net, but I 
just got confused. Then, suddenly I got some class for something, 
checked out the code and my brain just snapped. "aaah, THAT's how it's 
done!". It wasn't well documented, just nicely structured and easy to 
read and understand.

You'll get it one day. Until then - do what you feel is the best thing 
for you to use and understand.

This might not have helped you at all, it's just my story.

//Simon

Ryan A wrote:
Hi,
I myself never really create classes to use in my projects, if I ever use
classes its only because they come from someone else (eg phpclasses.org), I
find using the non OO approach much easier to understand.
Just my 2 cents.
Cheers,
-Ryan


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


Re: [PHP] Re: classes v. functions

2003-07-19 Thread olinux
I'm quite new to OOP myself, but these two articles
helped my understanding a lot

See the sidebar - Classes and Object Oriented
Programming
http://webreference.com/perl/xhoo/php1/5.html

Taking PHP the OO way
http://phpmag.net/itr/online_artikel/psecom,id,284,nodeid,114.html


olinux


--- Sam Baum <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> am Friday 18 July 2003 23:08 schrieb Andu:
> 
> > This may show my ignorance or my refusal to take
> for granted something I
> > don't fully understand but I have a hard time
> figuring out the advantage
> > of using classes as opposed to just functions. I
> am certainly new to php
> > and at first sight classes seemed to cut a lot of
> corners but so do
> > functions (with which I have more experience). The
> more I read about
> > classes the deeper the confusion. Anyone can
> enlighten me?
> 
> Im programming for a few years now in PHP. After
> trying to use classes i
> dont see their point either. In most cases if i need
> a class-like structure
> i do something like this:
> 
> function thing_new() {
> return ++$GLOBALS['thing_resource'];
> }
> 
> function thing_put($stuff, $res=NULL) {
> if (is_null($res)) $res =
> $GLOBALS['thing_resource'];
> $GLOBALS['thing_stuff'][$res] = $stuff;
> }
> 
> function thing_get($stuff, $res=NULL) {
> if (is_null($res)) $res =
> $GLOBALS['thing_resource'];
> return $GLOBALS['thing_stuff'][$res];
> }
> 
> Because there is no constraint to be more OO like in
> Java it doesnt makes
> sense. And this way you are more flexible.
> 
> 
> bg
> 
> Sam
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


__
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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



Re: [PHP] Re: classes v. functions

2003-07-19 Thread Sam Baum
Hi there, 

am Saturday 19 July 2003 16:30 schrieb Curt Zirzow:

> Sam Baum <[EMAIL PROTECTED]> wrote:
>> Hi,
>> 
>> am Friday 18 July 2003 23:08 schrieb Andu:
>> 
>> > This may show my ignorance or my refusal to take for granted something
>> > I don't fully understand but I have a hard time figuring out the
>> > advantage of using classes as opposed to just functions. I am certainly
>> > new to php and at first sight classes seemed to cut a lot of corners
>> > but so do functions (with which I have more experience). The more I
>> > read about classes the deeper the confusion. Anyone can enlighten me?
>> 
>> Im programming for a few years now in PHP. After trying to use classes i
>> dont see their point either. In most cases if i need a class-like
>> structure i do something like this:
>> 
>> function thing_new() {
>> return ++$GLOBALS['thing_resource'];
>> }
> 
> The biggest thing classes do is resolve name space issues, even with
> this method you have namespace issues with your function name and your
> variables.  

Sure i have to add and take care of the namespaces myself, but thats it and
the amount mental work compared to designing a class is imho lesser in my
way. And most times only 1 object of a class gets instanciated, which is to
much overhead in an application. And then u dont even need my construct.
And if you dont create an object and call the function in an static way
(via ::), then the whole benefit of the associated data is gone anyway and
the only thing you have is the namespace. So i dont give the Parser the
challenge of preparing a class representation and keep it simple. And at
last: no more copied objects. 

> A big downfall with classes, however is there speed.  Benchmarking a
> function call vs. a class->method call, results in a significant
> difference and even more if your using a lot of classes.

Ok i just assumed that, but good to know for sure. 



Sam

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



Re: [PHP] Re: classes v. functions

2003-07-19 Thread Curt Zirzow
Sam Baum <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> am Friday 18 July 2003 23:08 schrieb Andu:
> 
> > This may show my ignorance or my refusal to take for granted something I
> > don't fully understand but I have a hard time figuring out the advantage
> > of using classes as opposed to just functions. I am certainly new to php
> > and at first sight classes seemed to cut a lot of corners but so do
> > functions (with which I have more experience). The more I read about
> > classes the deeper the confusion. Anyone can enlighten me?
> 
> Im programming for a few years now in PHP. After trying to use classes i
> dont see their point either. In most cases if i need a class-like structure
> i do something like this:
> 
> function thing_new() {
> return ++$GLOBALS['thing_resource'];
> }

The biggest thing classes do is resolve name space issues, even with
this method you have namespace issues with your function name and your
variables.  This rather effects a lot of people who create libraries to
share with.

A big downfall with classes, however is there speed.  Benchmarking a
function call vs. a class->method call, results in a significant
difference and even more if your using a lot of classes.

In general, I only use small and nicely bundled classes that don't have
to do a lot of work, ie authentication, session.

> 
> Because there is no constraint to be more OO like in Java it doesnt makes
> sense. And this way you are more flexible.

And besides php wasn't designed/developed to be an OO language.


Curt.

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



Re: [PHP] Re: classes v. functions

2003-07-19 Thread Ryan A
Hi,
I myself never really create classes to use in my projects, if I ever use
classes its only because they come from someone else (eg phpclasses.org), I
find using the non OO approach much easier to understand.
Just my 2 cents.
Cheers,
-Ryan


- Original Message -
From: "Sam Baum" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, July 19, 2003 11:59 AM
Subject: [PHP] Re: classes v. functions


> Hi,
>
> am Friday 18 July 2003 23:08 schrieb Andu:
>
> > This may show my ignorance or my refusal to take for granted something I
> > don't fully understand but I have a hard time figuring out the advantage
> > of using classes as opposed to just functions. I am certainly new to php
> > and at first sight classes seemed to cut a lot of corners but so do
> > functions (with which I have more experience). The more I read about
> > classes the deeper the confusion. Anyone can enlighten me?
>
> Im programming for a few years now in PHP. After trying to use classes i
> dont see their point either. In most cases if i need a class-like
structure
> i do something like this:
>
> function thing_new() {
> return ++$GLOBALS['thing_resource'];
> }
>
> function thing_put($stuff, $res=NULL) {
> if (is_null($res)) $res = $GLOBALS['thing_resource'];
> $GLOBALS['thing_stuff'][$res] = $stuff;
> }
>
> function thing_get($stuff, $res=NULL) {
> if (is_null($res)) $res = $GLOBALS['thing_resource'];
> return $GLOBALS['thing_stuff'][$res];
> }
>
> Because there is no constraint to be more OO like in Java it doesnt makes
> sense. And this way you are more flexible.
>
>
> bg
>
> Sam
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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



[PHP] Re: classes v. functions

2003-07-19 Thread Jean-Christian IMbeault
I am sure someone will call this heresy, but if you really want OO don't
(Bdo it in PHP. If you are new to OO and start with PHP you will do
(Byourself a grat disfavour. OO programming in PHP is still not ready. If
(Byou try and program in OO in PHP you have to learn all of it's
(Bshortcomings and many "tricks" to get around them. And I promise that
(Bmore than once you will scratch your head and wonder why your object
(Bseems to have lost it's state or some variable never seems to get set
(Bproperly.
(B
(BJean-Christian Imbeault
(B
(B
(B-- 
(BPHP General Mailing List (http://www.php.net/)
(BTo unsubscribe, visit: http://www.php.net/unsub.php

[PHP] Re: classes v. functions

2003-07-19 Thread Sam Baum
Hi,

am Friday 18 July 2003 23:08 schrieb Andu:

> This may show my ignorance or my refusal to take for granted something I
> don't fully understand but I have a hard time figuring out the advantage
> of using classes as opposed to just functions. I am certainly new to php
> and at first sight classes seemed to cut a lot of corners but so do
> functions (with which I have more experience). The more I read about
> classes the deeper the confusion. Anyone can enlighten me?

Im programming for a few years now in PHP. After trying to use classes i
dont see their point either. In most cases if i need a class-like structure
i do something like this:

function thing_new() {
return ++$GLOBALS['thing_resource'];
}

function thing_put($stuff, $res=NULL) {
if (is_null($res)) $res = $GLOBALS['thing_resource'];
$GLOBALS['thing_stuff'][$res] = $stuff;
}

function thing_get($stuff, $res=NULL) {
if (is_null($res)) $res = $GLOBALS['thing_resource'];
return $GLOBALS['thing_stuff'][$res];
}

Because there is no constraint to be more OO like in Java it doesnt makes
sense. And this way you are more flexible.


bg

Sam

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



[PHP] Re: classes and functions in include files

2003-02-27 Thread David Eisenhart
yes (as has been said); the code in the included file adopts 'the scope in
the place at the point of the include statement'. Hence if you were to put
the the include statement in a function the vars in the included file would
have the scope of that function; included outside a function they'll have
global scope

David Eisenhart



"Sunfire" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> just a fast question here.. and the lotic probably isnt to bright on my
part
> and i think i know the answer to this question too but just to make
sure...
> if you can include variables in an include file and use them outside that
> file (in the file that includes that file that is) then can you do the
same
> with classes and functions
>
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.458 / Virus Database: 257 - Release Date: 2/24/2003
>





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



[PHP] Re: classes and functions in include files

2003-02-27 Thread rush
"Sunfire" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> just a fast question here.. and the lotic probably isnt to bright on my
part
> and i think i know the answer to this question too but just to make
sure...
> if you can include variables in an include file and use them outside that
> file (in the file that includes that file that is) then can you do the
same
> with classes and functions

yap.

rush
--
http://www.templatetamer.com/




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



[PHP] Re: Classes vs. Functions

2002-07-18 Thread Richard Lynch

>Could someone please explain the difference between classes and functions
>and how to use a class. I write alot of PHP, but I never understood this at
>all. I use an include statement in many of my pages and include a file with
>a bunch of functions. For instance, I might have a function called stock();
>In the page I am using I include the file that has this function and I call
>it like this:
>
>stock($Sym);
>
>I am wondering if I am doing it the wrong way. So I need to better
>understand classes. What is one, and why would you use it?

You can safely ignore classes for the rest of your PHP coding life. :-)

Classes are *MOST* useful when:

Multiple programmers are building a large application, and you want to force
some structure into that insanity.

You are creating a "library" to distribute, and you want to minimize the
number of functions/variables that might conflict with other people's source
code.

You are modeling real-world objects with specific behaviours in your code.

The way you are doing it is *FINE*.

If you wanted to give away your stock() functions to everybody else, you
might want to create a class:

create class chris_cranes_stock_functions{
  function stock($sym = 'ZEND'){
.
.
.
  }
}

Then, if the guy who uses your code already *HAS* a 'stock' function, yours
won't be in the way, because you've buried it inside your class.

But it's probably not going to magically increase the readability or
reliability of your code to just start throwing class objects in there for
the fun of it.

Your current usage of include/function is perfectly fine.

-- 
Like Music?  http://l-i-e.com/artists.htm


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




[PHP] Re: Classes Constructor syntax

2002-07-17 Thread Matthew Gray

PHP does not support multiple constructors. But, It does support 
variable argument lists, so you can fake it with func_get_args() and 
func_get_num_args():

function issue() {

if( func_get_num_args() > 0 ) {
   
$args = func_get_args()

} else {

 // do something else...
}
}

Matt

David Russell wrote:

> Hi all,
>
> I am finally spending some time converting a million and one functions 
> into a class - this is for a software issue tracking system.
>
> I have:
>
> class issue {
>   var
>   var
>   ...
>
>   function issue() { //default constructor
> //initialise all variables to defaults, and start getting the 
> stuff from forms
>   }
>
>   function issue($number) { //1 variable constructor
> // Query database and populate variables accordingly
>   }
> }
>
> My question is: will this work? does PHP OOP support more than one 
> constructor? If my syntax is wrong, please let me know the correct 
> syntax.
>
> Thanks
>
> David R
>



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




[PHP] Re: Classes??

2002-04-21 Thread Smileyq

yes you can put as many classes as you want inside a file doesn't matter.



In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Gerard Samuel) 
wrote:

> Maybe a simple question.
> But can one file contain 2 or more classes??
> Thanks
>

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




[PHP] Re: classes & $this->

2002-02-01 Thread shann

try $this->http://www.zend.com/zend/tut/class-intro.php

shann.



"Phil Schwarzmann" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Can anyone direct me to a nice site that will take my hand and walk me
> through the basics of classes and $this->
>
> Ive written a few really good PHP sites and haven't had to use either of
> the two and Im sure Im missing out on some essentials to good coding.
>
> Thanks!
>



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




[PHP] Re: Classes within classes (Should I do this?)

2001-12-05 Thread Yasuo Ohgaki

Cameron Just wrote:

> Hi,
> 
> Is this a bad thing to do have a class stored within another class?
> 
> I would also like to store an array of another class within a class. 
> 
> It seems to work apart from the fact that I can't reference an array of 
> class directly.
> ie
> $test_array[0]->get();
> This gives an error.


There is nothing wrong storing array of classes in a class.

$obj->array_of_obj[0]->method() 

works.


or array of classes
$array_of_obj[0]->method().
works.
-- 
Yasuo Ohgaki


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




[PHP] Re: Classes and functions

2001-11-28 Thread Roko Roic

> I'm writing a class for POP3 access and I want some of the internal
> functions to be private, like the mime decoding stuff.
>
> Is there any way to do this? I found nothing in the docs :(

Unfortunately, PHP does not understand terms private, public, protected...
PHP coders adopted a coding standard to name all 'private' methdods like

_methodName()

i.e. Beginning with an underscore.

That's the best you can do, so live with it :)

Cheers
Roko



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




[PHP] RE: Classes and arrays

2001-05-09 Thread Tim Ward

when you reference a property of a class you don't need to say it's a
variable, 
so use $this->item[] instead of $this->$items[$id] and it works okay. I
haven't quite worked out why it went wrong in the way it did ... and that'll
worry me until I do.

Tim Ward
Senior Systems Engineer

Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html


> -Original Message-
> From: Stefan Kostopoulos [mailto:[EMAIL PROTECTED]]
> Sent: 08 May 2001 20:31
> To: [EMAIL PROTECTED]
> Subject: Classes and arrays
> 
> 
> Hi!
> 
> Can anybody explain to me why this script outputs:
> 
> oneone
> 
> instead of:
> 
> zeroone
> 
> ???
> 
> Thanks,
> 
> stefan
> 
> 
>  class Cart {
> var $items;  // Items in our shopping cart
>
> function add_item ($id,$text) {
> $this->$items[$id] = $text;
> }
>
>function output($id){
>   
>   echo $this->$items[$id];
>}
> 
> }
> 
> 
> $c = new Cart;
> $c->add_item(0,"zero");
> $c->add_item(1,"one");
> $c->output(0);
> $c->output(1);
> 
> 
> ?>
> 

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