to initialize instance variables and are accessible throughout the class. An anonymous hidden method called initializer allows to evaluate an expression immediately after the object has been built. class person first_name last_name = object val full_name = first_name ^ " " ^ last_name initializer print_endline("Hello there, I am " ^ full_name ^ ".") method get_last_name = last_name end;; let alonzo = new person "Alonzo" "Church" in (*Hello there, I am Alonzo Church.*) print_endline alonzo#get_last_name (*Church*) PHP In PHP version 5 and above, the constructor is a method named __construct() (notice that it's a double underscore), which the keyword new automatically calls after creating the object. It is usually used to automatically perform initializations such as property initializations. Constructors can also accept arguments, in which case, when the new statement is written, you also need to send the constructor arguments for the parameters. class Person { private string $name; public function __construct(string $name): void { $this->name = $name; } public function getName(): string { return $this->name; } } In PHP, a class is only allowed to declare a maximum of one constructor method. Static methods, factory classes or optional constructor arguments are some ways to facilitate multiple ways to create objects of a PHP class. Perl 5 In Perl programming language version 5, by default, constructors are factory methods, that is, methods that create and return the object, concretely meaning create and return a blessed reference. A typical object is a reference to a hash, though rarely references to other types are used too. By convention the only constructor is named new, though it is allowed to name it otherwise, or to have multiple constructors. For example, a Person class may have a constructor named new as well as a constructor new_from_file which reads a file for Person attributes, and new_from_person which uses another Person object as a template. package Person; # In Perl constructors are named 'new' by convention. sub new { # Class name is implicitly passed in as 0th argument. my $class = shift; # Default attribute values, if you have any. my %defaults = ( foo => "bar" ); # Initialize attributes as a combination of default values and arguments passed. my $self = { %defaults, @_ }; # Check for required arguments, class invariant, etc. if ( not defined $self->{first_name} ) { die "Mandatory attribute missing in Person->new(): first_name"; } if ( not defined $self->{last_name} )