Jump to content

enum


aspnetguy

Recommended Posts

is this the correct way to define an enum??? I am using it in a class

class className{     public enum Section     {          Page, Menu, Upload, Templates      };}

This is actually for a C/C++ example but I noticed alot about PHP is similar to C++.

Link to comment
Share on other sites

I don't think it has enums per se, but you can always just define constants. Here's an example from the Class Constants page:

<?phpclass MyClass{   const constant = 'constant value';   function showConstant() {       echo  self::constant . "\n";   }}echo MyClass::constant . "\n";$class = new MyClass();$class->showConstant();// echo $class::constant;  is not allowed?>

Link to comment
Share on other sites

This is actually for a C/C++ example but I noticed alot about PHP is similar to C++.

That is because PHP was build of, well sort of, from C++ :) Am I right?C++ is a lower language, all languages we use right now for site building, are higher and mean they are "easier" and more constructive, but based on a lower language :) Look at Paskal and Basic, those are high languages too :)
Link to comment
Share on other sites

That is because PHP was build of, well sort of, from C++ :) Am I right?C++ is a lower language, all languages we use right now for site building, are higher and mean they are "easier" and more constructive, but based on a lower language :) Look at Paskal and Basic, those are high languages too :)

Sorry I wasn't clear...I got the example from C++ but needed to use enum in PHP..which I guess is not possible.
Link to comment
Share on other sites

That is because PHP was build of, well sort of, from C++ :) Am I right?C++ is a lower language, all languages we use right now for site building, are higher and mean they are "easier" and more constructive, but based on a lower language :) Look at Paskal and Basic, those are high languages too :)

This is the family tree for PHP, courtesy of my sweet O'Reilly poster:
PHP4(2000)  PHP1(1995)    Perl5(1994)      Perl1(1987)        SH(1971)        Nawk(1985)          Awk(1978)            C(1971)              CPL(1963)                ALGOL(1958)                  FORTRAN(1954)

Perl 1 was based off both SH and Nawk, that's what the indenting is about.This is for C++:

C++(1983)  C with Classes(1980)    C(K&R; 1978)      C(1971)        CPL(1963)          ALGOL(1958)            FORTRAN(1954)    Smalltalk(1980)      BASIC(1964)      Simula(1964)        ALGOL(1958)          FORTRAN(1954)

So both of them have the C language in their family tree, but after that they diverged. PHP is based mostly off of Perl, but Perl is based off C (via Nawk and Awk).When people refer to "high-level" or "low-level" programming languages, it basically describes the level of abstraction that the language gives to the programmer. That means that a language like x86 assembly, in which you write specific processor commands to move things in and out of registers and memory and perform simple calculations, is a low-level language, because you are basically speaking directly to hardware. Everything that you are familiar with, from C to Perl to PHP to Java to Javascript, are high-level languages, because the code you write goes through many transformations (compilation, interpretation, linking, whatever) before the hardware actually executes it. High-level languages abstract the hardware away so that you don't need to know what the hardware platform is in order to write code, PHP code will run on any platform that the PHP engine will run on. x86 assembly, on the other hand, will only run on a processor that implements the x86 instruction set, but assembly and other low-level languages are many orders of magnitude faster than high-level languages, especially the interpreted ones like PHP, ASP, and Java.With regard to C++/PHP, I think that when they were implementing object orientation for PHP5 that they took a lot of leads from both C++ and Java.

Link to comment
Share on other sites

...Everything that you are familiar with, from C to Perl to PHP to Java to Javascript, are high-level languages, because the code you write goes through many transformations (compilation, interpretation, linking, whatever) before the hardware actually executes it. High-level languages abstract the hardware away so that you don't need to know what the hardware platform is in order to write code,...

Exactly :) that was what I meant with higher and lower. I just translated the Dutch words we use, unaware that in English it is a bit different from just "higher" and "lower" :) Anyway, we are ghetting more and more offtopic by the day :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...