Forum Moderators: coopster

Message Too Old, No Replies

User-defined types

         

Clinton Labombard

7:45 am on Nov 4, 2006 (gmt 0)

10+ Year Member



Is it possible to create user-defined types in PHP (and how do I do that) or is that something I'll get with Perl?

eelixduppy

3:49 pm on Nov 5, 2006 (gmt 0)



I think if maybe we have a better idea of what you are trying to do it will help us answer your question fully.


The type of a variable is usually not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which that variable is used.

[us2.php.net...]

Also, you may want to refer to Type Juggling [us2.php.net].

Good luck!

Clinton Labombard

9:08 pm on Nov 6, 2006 (gmt 0)

10+ Year Member



A user-defined type defines a type defined by the user?

Okay, what it does is links some code to a variable. Here's a pseudo-code example:

myType = new Type {
code...
}

myType var = "something";

..so, whenever myType is used, whatever data belonging to 'var' is passed to the subroutine belonging to 'myType'. The code can do something with that data, check it for validity, etc.

eelixduppy

9:11 pm on Nov 6, 2006 (gmt 0)



You confused me by saying "user-defined". I was thinking something different, and apparently everyone who read this thread did too ;)

Anyway, you are looking for Classes [us2.php.net].

That tutorial on the basics should be sufficient for now :)

Best of luck!

Clinton Labombard

11:12 pm on Nov 7, 2006 (gmt 0)

10+ Year Member



...classes /do/ that... well slap m'fro...