Welcome to WebmasterWorld Guest from 50.16.84.67

Forum Moderators: coopster & jatar k

User-defined types

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

5+ 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?
3:49 pm on Nov 5, 2006 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



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!

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

5+ 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.

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

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



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!

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

5+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month