Skip to content

Location::getLocation

James Cobban edited this page Mar 25, 2022 · 3 revisions

Location::getLocation($idlr)

Up: class Location

This is a static factory method for an instance of Location that takes one parameter:

parameter description
$idir the value of field 'idir' or 'location'

This returns a shared instance of class Location which is identified by the value of 'idir' or 'location'. This differs from new Location(array('idlr' => $idlr)) or new Location(array('location' => $idlr)) in that if the current application process has previously created an instance of class Person for that value of 'idir' or 'location', either by calling Location::getLocation($idlr) or by new Location(array('idlr' => $idlr)) then Location::getLocation($idlr) returns that existing instance rather than creating a new instance.

This has two advantages:

  1. If the current thread has previously created an instance then this is much faster than creating a new entry, which would, among other things, require reading the record from the database again.
  2. If all parts of the application use Location::getLocation($idlr) then all parts of the application will be using the same copy of the object and all changes made by any part of the application will be reflected when the instance is saved.

Next: $location->getIdlr()

Clone this wiki locally