memory_get_peak_usage> <magic_quotes_runtime
Last updated: Fri, 03 Feb 2012

main

(No version information available, might only be in SVN)

mainMarcador para main()

Descrição

Não existe função com o nome de main() com exceção no código fonte do PHP. No PHP 4.3.0, um novo tipo de gerenciamento de erro foi introduzido no fonte do PHP (php_error_docref). Uma das funções é prover links para as páginas de manual do PHP nas mensagens de erros quando a diretiva de configuração html_errors (on por padrão) e docref_root (on por padrão até o PHP 4.3.2) estiverem definidas.

Algumas vezes as mensagens de erro se referem a uma página de manual para a função main(), é por isso que esta pagina existe. Por favor adicione um comentário do usuário abaixo que mencione qual função do PHP causou um erro que foi ligado a função main() e será corrigido e propriamente documentado.

Eros conhecidos que apontam para main()
Nome da função Não aponta para aqui a partir do
include() 5.1.0
include_once() 5.1.0
require() 5.1.0
require_once() 5.1.0



memory_get_peak_usage> <magic_quotes_runtime
Last updated: Fri, 03 Feb 2012
 
User Contributed Notes
main
logan at loganmcgrath dot com
14-Feb-2009 04:21
I've always seen "main()" used as below. You basically define all the functions required to execute your script, then throw all the other code in the Main function for when it executes. Keeps things nice and modular :D

<?php

 
// grab our necessary "header" files and settings
 
include '../includes/bootstrap.php';

 
// execute our script
 
Main();

 
// this is "where it all happens"
 
function Main()
  {
   
$value = value_get();

   
value_output_to_buffer( $value );

    return;
  }

 
// we define all our functions and subroutines
  // at the bottom of the document so we don't
  // have to scroll all the way down just to figure
  // out what our code does

 
function value_get()
  {
    return
'This is a value!';
  }

  function
value_output_to_buffer( $value )
  {
    echo
$value;

    return;
  }

?>
yves dot vanhal at hogent dot be
28-Nov-2008 12:09
In an effort to separate PHP code as much as possible from the HTML code I use the following self-enforced standard:
* all PHP functions are above the <!DOCTYPE> or <HTML>
* the last function in the list in the PHP block is a function called main()
* within the <BODY> element the first thing I do to initialize the page is to make a call to the main function

This results in code looking like this:
<?php
function xxx() { }
function
yyy() { }
function
main() {
 
xxx() // execute call to other function
}
?>
<HTML>
<BODY>
<?php main() ?>
</BODY>
</HTML>

This way I hope my code will be readable for newbies and advanced programmers.
penny at mjollnir dot org
04-Jul-2008 08:29
if like me, you're working inside a framework where you can't require the file with the class definition before session_start is called, I found the following workaround:

$whatever = unserialize(serialize($_SESSION['whatevever']));

dirty hackish, but works.
Anonymous
26-Jun-2008 08:32
In addition to Maurice's comments:

the "The script tried to execute a method or access a property of an incomplete object" message can appear also if you store your objects in session, and rename class during that session.

For example, you have class "class_name", and there is a class variable "$class_var = new class_name".

If you decide to rename your class, you would have "$class_var = new class_new_name".

This re-naming will result in abovementioned error message if you store $class_var in session.

Solution: clean-up session variable, then error disappears.
deryckchan [ATT] gmail D0T C0M
21-Feb-2008 12:10
To put it simple: main() refers to anything running in the current PHP script file that isn't part of any function.
MagicalTux at kinoko dot fr
28-Nov-2007 04:31
Additional note about what Maurice said: you can also use an __autoload function which will get called as the session/var is unserialized.

This will allow you to not preload all possible classes before loading a session, and let them be loaded dynamically. Check http://php.net/oop5.autoload for more details about this magic function.
Maurice
01-May-2006 03:12
Notice: main() [function.main]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "<classname>" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in <filename> on line <line>

You get this error if you have and object in your $_SESSION array and you call session_start() before you have loaded your included classes.

memory_get_peak_usage> <magic_quotes_runtime
Last updated: Fri, 03 Feb 2012