Modernize PHP output
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Non vengono indicati file sorgente, punti di ingresso o test. Inizia individuando il generatore PHP e i relativi test del codice generato, quindi confronta l’output attuale con il target PHP 8.5 proposto per enum, property hooks, tipizzazione e campi ripetuti. Per considerare il lavoro completato sono necessari un ambito concordato e criteri di compatibilità per il target di compilazione moderno.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What language does this apply to?
If it's for proto2, proto3, or an edition? All 3
If it's a generated code change, what programming language? PHP
Describe the problem you are trying to solve.
The docs have some outdated notions on PHP language features. Furthermore, modern features like property hooks means the resulting code can be a lot easier to use without requiring consumers to read a PHP protobuf specific manual.
Describe the solution you'd like
Enums
PHP Now supports enums.
// Current
class TestEnum {
const DEFAULT = 0;
const A = 1;
}
// Desired
enum TestEnum: int {
case DEFAULT = 0;
case A = 1;
}
Property hooks
PHP now supports property hooks, this means that much of the custom instrumentation can be simplified.
For example, here's an extract of a generated class from Opentelemetry, a LogRecord
class LogRecord extends \Google\Protobuf\Internal\Message {
public function __construct($data = NULL) {
\GPBMetadata\Opentelemetry\Proto\Logs\V1\Logs::initOnce();
parent::__construct($data);
}
public function getTimeUnixNano()
{
return $this->time_unix_nano;
}
/**
* time_unix_nano is the time when the event occurred.
* Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970.
* Value of 0 indicates unknown or missing timestamp.
*
* Generated from protobuf field <code>fixed64 time_unix_nano = 1;</code>
* @param int|string $var
* @return $this
*/
public function setTimeUnixNano($var)
{
GPBUtil::checkUint64($var);
$this->time_unix_nano = $var;
return $this;
}
}
With property hooks we can simplify this:
class LogRecord extends \Google\Protobuf\Internal\Message {
/**
* time_unix_nano is the time when the event occurred.
* Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970.
* Value of 0 indicates unknown or missing timestamp.
*
* Generated from protobuf field <code>fixed64 time_unix_nano = 1;</code>
* @return int|string
*/
protected int $time_unix_nano = 0 {
set(int|string $value) {
GPBUtil::checkUint64($value);
$this->time_unix_nano = $value
}
};
public function __construct($data = NULL) {
\GPBMetadata\Opentelemetry\Proto\Logs\V1\Logs::initOnce();
parent::__construct($data);
}
}
Consuming the code in userland then becomes a lot more "native":
$logRecord = new LogRecord();
$logRecord->xxx = 12345;
$logRecord->yyy = 12345;
$logRecord->zzz[] = "additional value";
Repeated fields
Since we're generating code, for repeated fields we could also introduce simple collection objects. This removes the need for a get, modify, set.
Describe alternatives you've considered
These are just some ideas to modernize the generated code. Functionally today's code works, but it doesn't take advantage of modern PHP language features like enums, property hooks and typing that could improve the developer experience.
Additional context
I'd propose something like a php-modern compilation target that targets php 8.5 x64.
From PHP 9 onwards dropping 32 bit versions altogether is being considered. I'd argue that even now for a modern compilation target, the special uInt64 checks can be simplified even further, or just rely on the PHP type system.
- Lingua principale
- C++
- Stelle
- 72.2k
- Fork
- 16.4k
- Merge medio
- 1g 8h
- PR unite (30g)
- 342
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di protocolbuffers/protobuf
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
protocolbuffers/protobuf#31768 ·
I maintainer di solito rispondono entro 1 giorno
-
feature request packaging & distribution python
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
protocolbuffers/protobuf#31654 ·
I maintainer di solito rispondono entro 1 giorno
-
google-protobuf 0.36.2-release fails to compile for ARMv7: @progbits rejected in global_asm!Forse già presa @farisbasha l’ha presa 2 giorni fa. Apertabug help wanted rust
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
protocolbuffers/protobuf#31619 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Null pointer passed to memcpy in lupb_decode() when the second argument is nilForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug help wanted lua
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
protocolbuffers/protobuf#31392 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
upb: JSON encoder does not range-check Duration and Timestamp nanos (signed overflow on -2^31)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
protocolbuffers/protobuf#31032 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di protocolbuffers/protobuf
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
I maintainer di solito rispondono entro 7 giorni
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
microsoft/DirectXShaderCompiler#9155 ·
I maintainer di solito rispondono entro 2 giorni
-
Errors in 1.20 proseApertaCampaign DiD Campaign EI Campaign HttT Campaign TDG Campaign TSG Campaign WoF Enhancement Help Prose Stable 1.20
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
wesnoth/wesnoth#11749 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno