Mostrando postagens com marcador php para certificação. Mostrar todas as postagens
Mostrando postagens com marcador php para certificação. Mostrar todas as postagens

segunda-feira, 13 de agosto de 2012

Status CODE HTTP

Uma lista completa de valores númericos do retorno de status de HTTP request. Conforme a seguir

Antes de ir a fundo podemos classificar assim:

Retornos 1xx = Informational, 2xx = Success, 3xx = Redirection, 4xx = Unauthorized, 5xx Error



(Util para certificação de tecnologias voltadas para a web, provas, concurso e etc...)

Success 2xx

These codes indicate success. The body section if present is the object returned by the request. It is a MIME format object. It is in MIME format, and may only be in text/plain, text/html or one fo the formats specified as acceptable in the request.


OK 200

The request was fulfilled.


CREATED 201

Following a POST command, this indicates success, but the textual part of the response line indicates the URI by which the newly created document should be known.


Accepted 202

The request has been accepted for processing, but the processing has not been completed. The request may or may not eventually be acted upon, as it may be disallowed when processing actually takes place. there is no facility for status returns from asynchronous operations such as this.


Partial Information 203

When received in the response to a GET command, this indicates that the returned metainformation is not a definitive set of the object from a server with a copy of the object, but is from a private overlaid web. This may include annotation information about the object, for example.


No Response 204

Server has received the request but there is no information to send back, and the client should stay in the same document view. This is mainly to allow input for scripts without changing the document at the same time.


Error 4xx, 5xx

The 4xx codes are intended for cases in which the client seems to have erred, and the 5xx codes for the cases in which the server is aware that the server has erred. It is impossible to distinguish these cases in general, so the difference is only informational.
The body section may contain a document describing the error in human readable form. The document is in MIME format, and may only be in text/plain, text/html or one for the formats specified as acceptable in the request.


Bad request 400

The request had bad syntax or was inherently impossible to be satisfied.


Unauthorized 401

The parameter to this message gives a specification of authorization schemes which are acceptable. The client should retry the request with a suitableAuthorization header.


PaymentRequired 402

The parameter to this message gives a specification of charging schemes acceptable. The client may retry the request with a suitable ChargeTo header.


Forbidden 403

The request is for something forbidden. Authorization will not help.


Not found 404

The server has not found anything matching the URI given


Internal Error 500

The server encountered an unexpected condition which prevented it from fulfilling the request.


Not implemented 501

The server does not support the facility required.


Service temporarily overloaded 502 (TO BE DISCUSSED)

The server cannot process the request due to a high load (whether HTTP servicing or other requests). The implication is that this is a temporary condition which maybe alleviated at other times.


Gateway timeout 503 (TO BE DISCUSSED)

This is equivalent to Internal Error 500, but in the case of a server which is in turn accessing some other service, this indicates that the respose from the other service did not return within a time that the gateway was prepared to wait. As from the point of view of the clientand the HTTP transaction the other service is hidden within the server, this maybe treated identically to Internal error 500, but has more diagnostic value.
Note: The 502 and 503 codes are new and for discussion, September 19, 1994

Redirection 3xx

The codes in this section indicate action to be taken (normally automatically) by the client in order to fulfill the request.

Moved 301

The data requested has been assigned a new URI, the change is permanent. (N.B. this is an optimisation, which must, pragmatically, be included in this definition. Browsers with link editing capabiliy should automatically relink to the new reference, where possible)
The response contains one or more header lines of the form
       URI: <url> String CrLf

Which specify alternative addresses for the object in question. The String is an optional comment field. If the response is to indicate a set of variants which each correspond to the requested URI, then the multipart/alternative wrapping may be used to distinguish different sets


Found 302

The data requested actually resides under a different URL, however, the redirection may be altered on occasion (when making links to these kinds of document, the browser should default to using the Udi of the redirection document, but have the option of linking to the final document) as for "Forward".
The response format is the same as for Moved .


Method 303

 Method: <method> <url>
 body-section
Note: This status code is to be specified in more detail. For the moment it is for discussion only.
Like the found response, this suggests that the client go try another network address. In this case, a different method may be used too, rather than GET.
The body-section contains the parameters to be used for the method. This allows a document to be a pointer to a complex query operation.
The body may be preceded by the following additional fields as listed.


Not Modified 304

If the client has done a conditional GET and access is allowed, but the document has not been modified since the date and time specified in If-Modified-Sincefield, the server responds with a 304 status code and does not send the document body to the client.
Response headers are as if the client had sent a HEAD request, but limited to only those headers which make sense in this context. This means only headers that are relevant to cache managers and which may have changed independently of the document's Last-Modified date. Examples include Date , Server and Expires .
The purpose of this feature is to allow efficient updates of local cache information (including relevant metainformation) without requiring the overhead of multiple HTTP requests (e.g. a HEAD followed by a GET) and minimizing the transmittal of information already known by the requesting client (usually a caching proxy).


Original: http://www.w3.org/Protocols/HTTP/HTRESP.html

quinta-feira, 26 de julho de 2012

Late Static Binding no PHP

Late Static Binding existe a partir do PHP 5.3 e a maioria das explicações não são muito claras e por isso essa funcionalidade fica meio na... nuvem! 


A documentação do PHP define o Late Static Binding como "maneira de referenciar a classe chamada no contexto de herança estática"
ENTENDEU? 


Esta definição apesar de palavras bem usadas no nosso dia a dia não deixou muito claro a sua finalidade e ai ficamos muuito confusos... Felizmente esse é o tipo de conceito que não se entra na cabeça de "prima" e para ajudar a documentação do PHP tem bastante exemplo.

Chega de papo, a melhor forma de entender isso é vendo o CÓDIGO!

Para usar a Late Static Binding, precisamos de uma classe que herda de outra classe e alguns métodos estáticos para sobreescrevemos. Veja:

Late static binding - php 5.3
  1. class classePai {
  2.    
  3.     public static function normalCall() {
  4.         self::calledMethod();
  5.     }  
  6.     public static function lateStaticCall() {
  7.         static::calledMethod();
  8.     }  
  9.     public static function calledMethod() {
  10.         echo " Chamada na classe PAI \n";
  11.     }  
  12.    
  13. }
  14. class classeFilha extends classePai {
  15.    
  16.     public static function calledMethod() {
  17.         echo "Chamada na classe Filha \n";
  18.     }  
  19.    
  20. }


Veja bem, temos a classeFilha que extende da classePai...
Na classePai temos 3 métodos estáticos, normalCalllateStaticCallcalledMethod na classe filha temos apenas um método estático o calledMethod

Percebam que tanto na filha quanto na pai temos a classe calledMethod certo?
Pois bem, se chamarmos o método estático normalCall tanto com a classe filha como a pai o resultado seria  Chamada na classe PAI  veja um pequeno exemplo do uso.


USANDO FORMA COMUM PARA CHAMAR OUTRO METODO ESTATICAMENTE
  1.  classePai::normalCall(); // Chamada na classe PAI
  2.  classeFilha::normalCall(); // Chamada na classe PAI


Ou seja, independente de chamar o método estático na filha ou na pai a função que a classe normalCall irá chamar sempre será a calledMethod da classe pai, pois é isso que o self esta fazendo.

Agora, se fizermos a mesma coisa mais trocando o self por static que é como esta implementado no método lateStaticCall a chamada seria diferente pois o Late Static Binding estaria em ação, veja:

USANDO LATE STATIC BINDING NO PHP
  1.  classePai::lateStaticCall(); // Chamada na classe PAI
  2.  classeFilha::lateStaticCall(); // Chamada na classe Filha


Fonte: PHP.net (como sempre, rs)

sábado, 14 de julho de 2012

SPL PHP

Se você nem imagina o que significa SPL no PHP é provavel que você veio aqui por culpa da certificação da ZEND (pois SPL esta no edital da prova), e eu já vou adiantando que você se deu muito bem pois a ideia é justamente esclarecer o SPL para vc aprender e ir bem na certificação!

SPL significa Standard PHP Library  que é uma coleção de interfaces e classes que servem para resolver problemas padrões da orientação a objetos no PHP.
Em resumo SPL fornece um conjunto padrão de interfaces para PHP5. O objetivo do SPL é implementar algumas interfaces de dados eficientes de acesso e classes para PHP. Funcionalmente ele é projetado para percorrer estruturas agregadas (qualquer coisa que você quer varrer). Estes podem incluir matrizes, conjuntos de resultados de banco de dados, árvores xml, listas de diretório ou de qualquer lista em tudo. Atualmente SPL lida com iteradores.


Agora você pensa: Legal, mais onde isso exatamente me ajuda? Eu sei que ver o Homer aqui comemorando é muito legal mas eu quero uma finalidade para a SPL... 

E ai eu te digo, vou repetir mais com outras palavras a explicação.... o SPL são interfaces e classes nativas do PHP que tem o intuito de resolver problemas que ocorrem com frequencia no desenvolvimento, como por exemplo uma interação de arrays e etc...

Agora melhorou né? Mais como funciona?... A SPL é dividida em categorias de acordo com a funcionalidade.

Eu não vou ficar escrevendo TUDO aqui pois seria replicar o que existe na documentação do PHP, mais vou dar um copy paste de uma classe que é a ArrayIterator, veja como é util.


A classe ArrayIterator

Introdução

Este iterator permite remover e modificar valores e chaves quando iterando arrays e objetos.
Quando você quiser iterar o mesmo array múltiplas vezes você precisa instanciar ArrayObject e criar instâncias de ArrayIterator que é consultado usando foreach ou chamando o método getIterator() manualmente.

Sinopse da classe

ArrayIterator implements Iterator Traversable ArrayAccess SeekableIterator Countable {
/* Métodos */
public void append ( mixed $value )
public void asort ( void )
public __construct ([ mixed $array = array() [, int $flags = 0 ]] )
public int count ( void )
mixed current ( void )
public array getArrayCopy ( void )
public void getFlags ( void )
mixed key ( void )
public void ksort ( void )
public void natcasesort ( void )
public void natsort ( void )
void next ( void )
public void offsetExists ( string $index )
public mixed offsetGet ( string $index )
public void offsetSet ( string $index , string $newval )
public void offsetUnset ( string $index )
void rewind ( void )
void seek ( int $position )
public string serialize ( void )
public void setFlags ( string $flags )
public void uasort ( string $cmp_function )
public void uksort ( string $cmp_function )
public string unserialize ( string $serialized )
bool valid ( void )
}

Seus métodos e funcionalidade


Informações completas sobre a a classe?
o PHP tem uma das melhores documentações do mundo, então é só acessar. 
http://www.php.net/manual/pt_BR/book.spl.php

Valeu!